#include<stdio.h> int main() { int n,sum=0; do { printf("请输入n的值:"); scanf("%d",&n); if(n<1) printf("输入错误,"); }while(n<1); while(n) { sum+=(n+1)*n; --n; } printf("sum=%d",sum); return 0; }
#include<stdio.h> #include <stdio.h> int main() { int i,s = 0,n; printf("请输入N的值 \n"); scanf("%d",&n); for( i = 1; i <= n; ++i){ s += i*(i+1); } printf("sum = %d\n",s); return 0; }