集合类的题~ 求解
遇到一个不会做的题 想了半天没得出答案~ 会的麻烦帮助下。不会写这个程序~ 1+(1+2)+(1+2+3)+(1+2+3+4)+……+(1+2+3+……+99+100)
[ 本帖最后由 cqlovesss 于 2012-1-16 20:34 编辑 ]
#include <stdio.h> int main(void) { int i, n, flag = 1; int sum = 0; char c; while (flag) { printf("Please input n:"); scanf("%d", &n); for (i = 1; i <= n; i++) sum += i * (n + 1 - i); printf("The result is : %d\n", sum); sum = 0; getchar(); printf("继续观察?(Y / N):"); c = getchar(); if ( c == 'Y' || c == 'y') flag = 1; else flag = 0; } printf("\n"); return 0; }