Input Format
輸入一正整數N
Output Format
輸出計算1+(1+2)+(1+2+3)+...到N的結果
user_6817964
c_cpp
3 years ago
234 B
2
Indexable
#include <stdio.h> // printf
int main()
{
int n;
scanf_s("%d", &n);
int total = 0;
for (int i = 1; i <= n; i++) {
int sum = 0;
for(int j = 1; j <= i; j++)
sum += j;
total += sum;
}
printf("%d", total);
}