반응형

1^2+2^2+3^2+...+n^2 의 값을 계산하여 출력하여 보자.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>
int main(void)
{
int a, b, total;
total = 0;
printf("n의 값을 입력하시오: ");
scanf("%d"&a);
for(b=1;b<=a;b++)
{
    total = total + b*b;
}
printf("계산값은 %d입니다.\n", total);
return 0;
}
cs




반응형

'컴퓨터 & 프로그래밍 & 전자공학 > C언어' 카테고리의 다른 글

순열(permutation)  (0) 2016.07.22
피보나치 수열  (0) 2016.07.22
실수의 거듭 제곱값  (0) 2016.07.21
1부터 n까지의 합  (0) 2016.07.21
별표 막대 그리기  (0) 2016.07.21

+ Recent posts