while do-while for break continue
while( ) ;
#include <stdio.h> 0 i int main(void) int meter; int i = 0; while(i < 3) meter = i * 1609; printf("%d %d \n", i, meter); i++; return 0;
i i< 3 () 0 (1) () 1 (1) () 2 (1) () 3 (0)
// while #include <stdio.h> int main(void) int n; int i = 1; printf(" : "); scanf("%d", &n); while (i <= 9) printf("%d*%d = %d \n", n, i, n*i); i++; 구구단중에서출력하고싶은단을입력하시오 return 0;
// while #include <stdio.h> int main(void) int n; printf("====================\n"); printf(" n n \n"); printf("====================\n"); n = 1; while (n <= 10) printf("%5d n++; return 0; %5d\n", n, n*n);
1 + 2 + 3 +... + n...
#include <stdio.h> int main(void) int i, n, sum; // printf(" :"); scanf("%d", &n); // // i= 1; // sum = 0; while(i <= n) sum += i; i++; // sum = sum + i;. // i = i + 1. printf("1 %d %d \n", n, sum); return 0;
// while #include <stdio.h> int main(void) int i, n, sum; i = 0; // sum = 0; // while (i < 5) printf(" : "); scanf("%d", &n); sum = sum + n; // sum += n;. i++; printf(" %d.\n", sum); return 0;
100, 200, 300, 400, 500, -1
// while #include <stdio.h> int main(void) int grade, n; float sum, average; //. n = 0; sum = 0; grade = 0; printf(" \n");
//. while (grade >= 0) printf(" : "); scanf("%d", &grade); sum += grade; n++; sum = sum - grade; //. n--; //. //. average = sum / n; printf(" %f.\n", average); return 0;
x, y. y 0 x. r x % y x y y r.
// while #include <stdio.h> int main(void) int x, y, r; printf(" (, ( ): ) "); scanf("%d%d", &x, &y); while (y!= 0) r = x % y; x = y; y = r; printf(" %d.\n", x); return 0;
if( )...... while( )......
int i = 1; while(i < 10) printf("\n"): i--; int i = 0; while(i < 3) printf("\n"): i++;. int i = 0; while(i < 3) ; printf("\n"): i++;.
do while()....
// do..while #include <stdio.h> 1--- 2--- 3--- int main(void). int i = 0; 1 do =1 printf("1--- \n"); printf("2---\n"); printf("3---\n"); printf(".\n"); scanf("%d", &i); while(i < 1 i > 3); printf(" =%d\n",i); return 0;
// #include <stdio.h> int main(void) char answer = 'm' char guess; int tries = 0; do printf(" : "); scanf(" %c", &guess); tries++; : a. : s. : b. : z. : m. =5 if( guess > answer ) printf(".\n"); if( (g guess < answer ) printf(".\n"); while(guess!= answer); printf(". =%d \n", tries); return 0;
for ( ; ; ) ;.. for...
int i; for(i = 0; i < 10; i++) printf("hello World!\n");
int i; for(i = 0; i < 10; i++) printf("hello World!\n"); 1 번째반복 0 참 반복 2 번째반복 1 참반복 3 번째반복 2 참반복 4 번째반복 3 참반복 5 번째반복 4 참반복 6 번째반복 5 참반복 7 번째반복 6 참반복 8 번째반복 7 참반복 9 번째반복 8 참반복 10 번째반복 9 참반복
// #include <stdio.h> int main(void) int i, sum; sum = 0; for(i = 1;i <= 10; i++) sum += i; // sum = sum + i; printf("1 10 = %d\n",sum); return 0;
// #include <stdio.h> int main(void) int i, n; printf(" :"); scanf("%d", &n); printf("====================\n"); printf(" i i \n"); printf("====================\n"); for(i = 1;i <= n; i++) printf("%5d %5d\n", i, i*i*i); return 0;
// #include <stdio.h> int main(void) long fact=1; int i, n; printf(" :"); scanf("%d", &n); for(i = 1;i <= n; i++) fact = fact * i; printf("%d! %d.\n",n,fact); return 0;
for (i =0; i<10; i+=2) printf("hello World!\n"); for (i = 1; i < 10; i *= 2 ) printf("hello World!\n"); for (i = 0; i < 100; i = (i * i) + 2 ) printf("hello World!\n"); for ( ; i<100; i++ ) printf("hello World!\n"); for (i = 0, k = 0; i < 100; i++ ) printf("hello World!\n"); for (printf(" ) ), i = 0; i < 100; i++ ) printf("hello World!\n");
// for * #include <stdio.h> int main(void) int x, y; for(y = 0;y < 5; y++) for(x = 0;x < 10; x++) printf("*"); printf("\n"); return 0;
#include <stdio.h> int main(void) int s, t; float score, total, average; for(s = 0;s < 20; s++) total = 0; for(t = 0;t < 5; t++) printf("%d % : "); scanf("%f", &score); total += score; average = total / 5.0; printf("%d : %f\n", average); return 0;
// break. #include <stdio.h> #include <math.h> int main(void) id) double v; while(1) printf(" : "); scanf("%lf", &v); if( v < 0.0 ) break; printf("%f %f.\n", v, sqrt(v)); return 0;
// break. #include <stdio.h> int main(void) float grade, sum = 0.0, average; int count = 0; while(1) printf(" : "); scanf("%f", &grade); if( grade < 0.00 ) break; count++; sum += grade; average = sum / count; printf(" %f.\n", average); return 0;
#include <stdio.h> int main(void) int x, y; for(y = 1; y < 10000; y++) for(x = 1; x < 50; x++) if( _kbhit() ) goto OUT; printf("*"); printf("\n"); OUT: return 0;
//. #include <stdio.h> int main(void) char letter; while(1) printf(" : "); scanf(" %c", &letter); if( letter == 'Q' ) break ; if( letter < 'a' letter > 'z' ) continue ; letter -= 32; printf(" %c.\n", letter); return 0;
// #include <stdio.h> #define RATE 0.07 // #define INVESTMENT 10000000 // #define YEARS 10 // int main(void) int i; double total = INVESTMENT; // printf("==============\n"); printf(" \n"); printf("==============\n"); ============== ============== 1 10700000.0 2 11449000.0 3 12250430.0 4 13107960.1 5 14025517.3 6 15007303.5 7 16057814.8 8 17181861.8 9 18384592.1 10 19671513.6 for(i = 1; i <= YEARS; i++) total = total * ( 1 + RATE ); // printf("%2d %10.1f\n", i, total); return 0;
#include <stdio.h> #define START_DAY 3 // #define DAYS_OF_MONTH 31 // int main(void) id) int day, date; printf("=====================\n"); printf(" \n"); printf("=====================\n"); for(day = 0; day < START_DAY ; day++) // printf(" "); // for(date = 1; date <= DAYS_OF_MONTH ; date++) if( day == 7 ) day = 0; // printf("\n"); day++; printf("%2d ", date); //. printf("\n=====================\n"); return 0;