#include <stdio.h>

int main() {
     /* 반복문 for
     for (초기식; 조건식; 증감식) {
          반복할 코드;
     }
     for문의 실행 순서
          1. 초기식
          2. 조건식
          3. 반복할 코드
          4. 증감식
          2 ~ 4를 조건이 거짓일 때까지 반복
          5. 조건식
          6. 반복할 코드
          7. 증감식 . . . 
     */
     
     for (int i = 1; i <= 5; i++) {
          printf("i는 %d\n", i);
     }

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

     int sum = 0;
     int a;
     for (a = 1; a <= 3; a++) {
          sum += a;
          printf("sum = %d\n", sum);
     }
     printf("%d\n", a);


     int total = 0;
     for (int b = 100; b >= 10; b--){
          total = total + b;
     }
     printf("total = %d\n", total);


     int total2 = 0;
     int b;
     for (b = 10; b <= 100; b++) {
          total2 += b;
     }
     printf("total2 = %d\n", total2);

     return 0;
}

Embed on website

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