#include <stdio.h>
void sum(int n); // 원랜 그냥 n으로 쓰고 정의할 때 int n으로 설정해줌 -> 선언 시에 괄호에서 설정!
int main(void)
{
sum(10);
sum(100);
return 0;
}
void sum(int n) // 반환값없이 프린트에프로 끝내놓고 함수명 앞에는 int라 해놓음 반환값없으니 void
{
int i;
int res = 0;
for (i = 1; i <= n; i++)
{
res += i;
}
printf("%d\n", res);
return;
}
/*int res;
res = (n * (n + 1)) / 2;
printf("%d\n", res);*/
To embed this project on your website, copy the following code and paste it into your website's HTML: