Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:牛人们帮帮忙啊,就是过不了,郁闷啊~~急救!!!wrongIn Reply To:牛人们帮帮忙啊,就是过不了,郁闷啊~~急救!!!wrong Posted by:cpp051000448166 at 2005-04-29 15:09:11 > #include <iostream> > #include <iomanip> > using namespace std; > int i; > double a[10],s[10]; > int jie(int n) > { > int sum=1; > for(int i1=1;i1<=n;i1++) > { > sum=sum*i1; > } > return sum; > } > double add(double p[],int n) > { > double sum; //这里有问题,没给sum初值,sum 的值是一个不确定的数,导致数组s[]的值出错 > for(int i2=0;i2<=n;i2++) > sum+=p[i2]; > return sum; > } > > void main() > { > a[0]=1; > for(i=1;i<10;i++) > { > a[i]=(double)1/jie(i); > } > cout<<"n e"<<endl; > cout<<"- -----------"<<endl; > for(i=0;i<10;i++) > { > s[i]=add(a,i); > } > for(i=0;i<3;i++) > { > cout<<i<<" "<<s[i]<<endl; > } > for(i=3;i<10;i++) > { > cout<<i<<" "<<setiosflags(ios::fixed)<<setprecision(9)<<s[i]<<endl; > } > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator