본문 바로가기

카테고리 없음

c/c++ 배열 요소 1-100까지 합 출력

#include <stdio.h>

 

int main() {
int array[100] = { 0, };
int total = 0;
for (int i = 0; i < 100; i++) {

array[i] = 1 + i;    // 0+1, 1+2, 3+3......
//array[i] = array[1] + i;
total = total + array[i];       //출력


}
printf("배열의 총 합은 : %d ", total);
}