While문
While(조건식) { // 조건식이 참일동안 반복
반복할 문장
};
int a= 1;
while(a<10){ // a 가 참일동안 반복
a = a*2 ;
}
printf(“%d” ,a ) ;
for 문
for( I = 0 ; i<3; i++ ){
a = a*2;
}
For ( i= 0 ; i<7; i+=2){
}
Do while문
Do {
A= a *2
} while (a<10) ;
6.2 – 반복문 활용 ( 다중 반복문 , break , continue; )
구구단 출력
#include <stdio.h>
int main() {
int a = 1;
for (int i = 1; i <= 9; i++){
a = i *2 ;
printf("2 X %d = %d\n ",i,a);
}
}
구구단 가로 출력
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 5
#include <stdio.h>
int main() {
int a = 1;
for (int j = 1; j<=9; j++ ){
for (int i = 2; i <= 9; i++){
a = i * j ;
printf("%d X %d = %d \t ",i,j,a);
}
printf("\n");
}
}
별 찍기
#include <stdio.h>
int main() {
for(int j =1 ; j <=5; j ++){
for(int i =0; i <j; i ++){
printf("*");
}
printf("\n");
}
}
break
중첩 반복문에서 break는 반복문 하나씩만 벗어난다.
break 는 무한 반복문 에서 if와 함께 주로 사용
while(1) , for ( ;1;)
continue
반복문 내에서 continue를 만나면 반복문 끝으로 이동
for ( int i = 1 ; i <=100 ; i++){
if( i%3 ==0) continue;
sum += i ;
}
printf("%d",sum);
'혼자 공부하는 C언어(C언어의 모든것)' 카테고리의 다른 글
함수 정리 (0) | 2023.02.26 |
---|---|
5.1 ~ 5.2 if 문과 switch ~case 문 (0) | 2023.02.25 |
4.2 – 비트 연산자와 그 외의 멋진 연산자 (0) | 2023.02.25 |
4.1 산술, 관계, 논리 연산자 (0) | 2023.02.25 |
3.2 데이터 입력 (0) | 2023.02.25 |