这道题是基本的输出格式问题,还是那句话细节决定成败。

代码
1 #include<stdio.h>
2 #include<math.h>
3
4  int main()
5 {
6 __int64 s,t;
7 double p,q;
8 while(scanf("%I64d",&s)!=EOF&&s)
9 {
10
11 p=log10((1.0*s)/6)+log10(1.0*(s+1))+log10(1.0*(s+2));
12 t=(int)p;
13 p=p-(int)p;
14 q=pow(10.0,p);
15 printf("%.2lfE%d\n",q,t);//注意数据类型的匹配
16 /*s*(s+1)(s+2)/6=q*10^n
17 因为:位权是10的共有t=(int)p个(取对数得到,和求整数的位数类似),
18 两边同时取对数,经移项可得q*/
19 }return 0;
20 }
21 /*科学计数法的表示挺多的:
22 c++的函数:
23 cout<<setiosflags(ios::fixed)<<setprecision(2)<<pow(10,a)<<'E'<<int(b)<<endl;
24 也可以对求和结果sum,处理
25 c=0;
26 while (sum>=10)
27 {
28 c++;
29 sum/=10;
30 }
31 printf ("%.2lfE%d\n",sum,c);
32
33 */

 

posted on 2010-10-03 21:51  role  阅读(615)  评论(0编辑  收藏  举报