题解 | #牛牛学数列4#
牛牛学数列4
http://www.nowcoder.com/practice/586b114f52034688879342ba45779081
#include<stdio.h>
int main() {
int val = 0, n, a = 0; //a暂存值
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) { //计算括号内值
a += j;
}
val += a; //计算结果
a = 0; //初始化a
}
printf("%d", val);
return 0;
}
int main() {
int val = 0, n, a = 0; //a暂存值
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) { //计算括号内值
a += j;
}
val += a; //计算结果
a = 0; //初始化a
}
printf("%d", val);
return 0;
}