#include <stdio.h>

int main() {
     //while문 
     // //초기값
     // while (조건) {
     //      //반복할 코드 (증감 포함);
     // }

     int i = 0;
     while (i <= 5) {
          printf("%d ", i++);
          //i++;
     }
     printf("\n");

     int a = 3;
     while (a > 0){
          printf("%d ", --a);
     }
     printf("\n"); 

     // 출력 결과가 6 7 8 9 10 나오는 while문 만들기
     int b = 5;
     while (b < 10) {
          printf("%d ", ++b);
     }
     printf("\n"); 

     // 10 ~ 100 합을 구하는 코드를 while문으로 작성하기 출력 결과 5005 - (11/1 for문을 참고)
     int total = 0;
     int c = 10;
     while (c <= 100) {
          total += c;
          c++;
     }
     printf("total = %d\n", total);

     //do-while문 : 무조건 한 번은 실행하고, 조건이 참인 동안 반복된다
     // do {
     //      반복할 코드;
     // } while (조건);
     int n1 = 3;
     do {
          printf("일단 한 번은 실행\n");
     } while (n1 < 0);
     
     int n2 = 1;
     do {
          printf("n2 = %d\n", n2);
          n2++;
     } while (n2 <= 6);


     // 출력 결과가 6 7 8 9 10 나오는 do-while문 만들기
     b = 5;
     do {
          printf("%d ", ++b);
     } while (b < 10);
     printf("\n"); 

     // 100 ~ 1000 합을 구하는 코드를 do-while문으로 작성하기 - 495550
     int j = 100, sum = 0;
     do {
          sum += j;
          j++;
     } while (j <= 1000);
     printf("%d\n", sum);


     return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: