1 3 0
1.00E0 1.00E1when N=1 ,There is 1 gold coins. when N=3 ,There is 1+3+6=10 gold coins.HintHint解题思路:1、这个大家都会:1+2+3+4+…n=n(n+1)/2 2、这个有些同学忘记了: 1*1+2*2+3*3+…+n*n=n(n+1)(2n+1)/6 3、合并后得到n(n+1)(n+2)/3即求和公式为:(1.0*n*n*n+3.0*n*n+2.0*n)/6.0=((n(n+1)/2)+(n(n+1)(2n+1)/6))/2源代码:#include <stdio.h> #include <math.h> #include <stdlib.h> int main() { int n,b; float a; while(scanf("%d",&n) && n) { a=(1.0*n*n*n+3.0*n*n+2.0*n)/6.0; b=(int)log10(a); //求得b为指数 printf("%.2lf",a/pow(10,b));//小数部分 printf("E%d\n",b); //指数部分 } system("pause"); return 0; }
原文地址:http://blog.csdn.net/zchlww/article/details/42583751