2010年3月份二C上机编程题答案

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

本答案仅供参考(请不要随意更改)A类数学表达式(1—10)(N)1、#includeconio.h#includestdio.hfloatfun(intm,intn){floatt1=1,t2=1,t3=1,i;for(i=1;i=m;i++)t1*=i;for(i=1;i=n;i++)t2*=i;for(i=1;i=m-n;i++)t3*=i;returnt1/(t2*t3);}main(){printf(P=%f\n,fun(12,8));}2#includeconio.h#includemath.h#includestdio.hfloatfun(){floatx1=0.0,x0;x0=x1;x1=cos(x0);while(fabs(x0-x1)=0.000001){x0=x1;x1=cos(x0);}returnx1;}main(){printf(Root=%f\n,fun());}3#includeconio.h#includestdio.hdoublefun(intn){doublef0=0,f1=1,fn;fn=f0+f1;while(fn=n){f0=f1;f1=fn;fn=f0+f1;}returnfn;}main()/*主函数*/{printf(%f\n,fun(1000));}4#includeconio.h#includestdio.hvoidfun(float*sn,intn){floati,t=1;*sn=0;for(i=0;i=n;i++){*sn+=t/(2*i+1);t=-t;}}main()/*主函数*/{intn=11;floats;fun(&s,n);printf(s=%fn=%d\n,s,n);}5#includeconio.h#includemath.h#includestdio.hdoublefun(intm){doubles=0,i;for(i=1;i=m;i++)s+=log(i);returnsqrt(s);}main(){printf(%f\n,fun(20));}6#includeconio.h#includestdio.h#includemath.hdoublefun(doublex,intn){doubles=x+1,i,t=1;for(i=2;i=n;i++){t*=i;s+=pow(x,i)/t;}returns;}main(){printf(%f\n,fun(0.3,10));}7#includestdio.h#includemath.hdoublefun(intn){doubles=0,i;for(i=1;i=n;i++)s+=1.0/(i*(i+1));returns;}main(){printf(%f,fun(10));}8#includestdio.h#includemath.hdoublefun(doubleeps){doubles=0,t=1,i,m=1;for(i=1;t/m=eps;i++){s+=t/m;t=t*i;m=m*(2*i+1);}return2*s;}main(){doublex;printf(Inputeps:);scanf(%lf,&x);printf(\neps=%lf,PI=%lf\n,x,fun(x));}9#includestdio.h#includemath.hdoublefun(doublex){doublei,t=1,m=1,s=0;for(i=1;fabs(m/t)=0.000001;i++){s=s+m/t;m*=(0.5+1-i)*x;t=t*i;}returns;}main(){doublex,s;printf(Inputx:);scanf(%lf,&x);s=fun(x);printf(s=%f\n,s);}10#includestdio.h#includemath.hdoublefun(doublex[10]){doubles=0,sum=0;inti;for(i=0;i10;i++)s=s+x[i];s=s/10;for(i=0;i10;i++)sum+=(x[i]-s)*(x[i]-s);returnsqrt(sum/10);}main(){doubles,x[10]={95.0,89.0,76.0,65.0,88.0,72.0,85.0,81.0,90.0,56.0};inti;printf(\nTheoriginaldatais:\n);for(i=0;i10;i++)printf(%6.1f,x[i]);printf(\n\n);s=fun(x);printf(s=%f\n\n,s);}B类最大值和最小值(1—4)1#includestdlib.h#includestdio.hvoidfun(inta[],intn,int*max,int*d){inti;*d=0;*max=a[0];for(i=0;in;i++)if(a[i]a[*d]){*d=i;*max=a[*d];}}main(){inti,x[20],max,index,n=10;randomize();for(i=0;in;i++){x[i]=rand()%50;printf(%4d,x[i]);}printf(\n);fun(x,n,&max,&index);printf(Max=%5d,Index=%4d\n,max,index);}2#includestdio.h#defineN80voidfun(int*s,int*t,int*k){inti;*k=0;for(i=1;i*t;i++)if(s[i]s[*k])*k=i;s[*t]=s[*k];*t=*t+1;}main(){inta[N]={876,675,896,101,301,401,980,431,451,777},i,n,mi;n=10;printf(\nTheoriginaldata:\n);for(i=0;in;i++)printf(%4d,a[i]);printf(\n);fun(a,&n,&mi);printf(Theindexofmaxis:%d\n,mi);printf(Theresult:\n);for(i=0;in;i++)printf(%4d,a[i]);printf(\n);}3#includeconio.h#includestdio.h#defineM3#defineN4voidfun(inttt[M][N],intpp[N]){inti,j;for(j=0;jN;j++){pp[j]=tt[0][j];for(i=1;iM;i++)if(tt[i][j]pp[j])pp[j]=tt[i][j];}}main(){intt[M][N]={{22,45,56,30},{19,33,45,38},{20,22,66,40}};intp[N],i,j,k;printf(Theoriginaldatais:\n);for(i=0;iM;i++){for(j=0;jN;j++)printf(%6d,t[i][j]);printf(\n);}fun(t,p);printf(\nTheresultis:\n);for(k=0;kN;k++)printf(%4d,p[k]);printf(\n);}4#includeconio.h#includestdio.hintfun(int*s,intt,int*k){inti;*k=0;for(i=1;it;i++)if(s[i]s[*k])*k=i;}main(){inta[10]={876,675,896,101,301,401,980,431,451,777},k;clrscr();fun(a,10,&k);printf(%d,%d\n,k,a[k]);}C类二维数组行列下标(1—11)1#includestdio.h#includeconio.h#includestdlib.h#defineN5intfun(inta[][N],intm){inti,j;for(i=0;iN;i++)for(j=i;jN;j++)a[i][j]*=m;}main(){inta[N][N],m,i,j;printf(*****Thearray*****\n);for(i=0;iN;i++){for(j=0;jN;j++){a[i][j]=rand()%20;printf(%4d,a[i][j]);}printf(\n);}dom=rand()%10;while(m=3);printf(m=%4d\n,m);fun(a,m);printf(THERESULT\n);for(i=0;iN;i++){for(j=0;jN;j++)printf(%4d,a[i][j]);printf(\n);}}}}2#includestdio.h#includeconio.hintfun(intarray[3][3]){intt,i,j;for(i=0;i2;i++)for(j=1;j3;j++){t=array[i][j];array[i][j]=array[j][i];array[j][i]=t;}}main(){inti,j;intarray[3][3]={{100,200,300},{400,500,600},{700,800,900}};for(i=0;i3;i++){for(j=0;j3;j++)printf(%7d,array[i][j]);printf(\n);}fun(array);printf(Convertedarray:\n);for(i=0;i3;i++){for(j=0;j3;j++)printf(%7d,array[i][j]);printf(\n);}}3#includestdio.h#includeconio.h#includestdlib.h#defineN5doublefun(intw[][N]){inti,j;doublesum=0;for(j=0;jN;j++)sum+=w[0][j]+w[N-1][j];for(i=1;iN-1;i++)sum+=w[i][0]+w[i][N-1];returnsum;}main(){inta[N][N]={0,1,2,7,9,1,9,7,4,5,2,3,8,3,1,4,5,6,8,2,5,9,1,4,1};inti,j;doubles;printf(*****Thearray*****\n);for(i=0;iN;i++){for(j=0;jN;j++){printf(%4d,a[i][j]);}printf(\n);}s=fun(a);printf(*****THERESULT*****\n);printf(Thesumis:%lf\n,s);}5#includestdio.hvoidfun(int(*s)[10],int*b,int*n,intmm,intnn){inti,j;*n=0;for(i=0;imm;i++)for(j=0;jnn;j++)b[(*n)++]=s[i][j];}main(){intw[10][10]={{33,33,33,33},{44,44,44,44},{55,55,55,55}},i,j;inta[100]={0},n=0;printf(Thematrix:\n);for(i=0;i3;i++){for(j=0;j4;j++)printf(%3d,w[i][j]);printf(\n);}fun(w,a,&n,3,4);printf(TheAarray:\n);for(i=0;in;i++)printf(%3d,a[i]);printf(\n\n);}6#inclu

1 / 67
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功