二级.docx
- 文档编号:10394211
- 上传时间:2023-05-25
- 格式:DOCX
- 页数:29
- 大小:27.85KB
二级.docx
《二级.docx》由会员分享,可在线阅读,更多相关《二级.docx(29页珍藏版)》请在冰点文库上搜索。
二级
上机编程题
1. 程序设计题:
z=f(x,y)=(3.14*x-y)/(x+y), 若x、y取值为区间[1,6]的整数,找出使z取最小值的x1、y1,并将x1、y1以格式"%d,%d" 写入到考生目录下新建文件design.dat。
#include
voidmain()
{ FILE*p;floatf(int x,int y),min;
intx,y,x1,y1;
// 此处起要求考生自己编制程序
min=100;
p=fopen(“design.dat”,“w”);
for(x=1;x<6;x++)
for(y=1;y<6;y++)
if(f(x,y) { min=f(x,y); x1=x; y1=y; } fprintf(p,“%d,%d”,x1,y1); // 答案: x1=1,y1=5 fclose(p); // 或 若x<=6及y<=6 则 x1=1,y1=6 } floatf(intu,intv) {return(3.14*u-v)/(u+v);} 4.程序设计题: 对x=1,2,...,10,求函数 f(x)=x-10*cos(x)-5*sin(x)的最大值,并将该数以格式"%.3f"写到考生目录下新建文件design.dat。 #include #include voidmain() { FILE*p;floatf(float),max,x; // 此处起要求考生自己编制程序 p=fopen(“design.dat”,“w”); max=f (1); for(x=2;x<=10;x++) if(max max=f(x); fprintf(p,”%.3f”,max); // 答案: 21.111 fclose(p); } floatf(floaty) { y=y-10*cos(y)-5*sin(y); return(y); } 6. 程序设计题: 数组元素x[i]、y[i]表示平面上某点坐标,统计10个点中同处在圆 (x-1)*(x-1)+(y+0.5)*(y+0.5)=25 和 (x-0.5)*(x-0.5)+y*y=36内的点数k,并将变量k的值以格式"%d"写到考生目录下新建文件design.dat。 #include #include voidmain() { FILE*p;inti,k=0; floatx[]={1.1,3.2,-2.5,5.67,3.42,-4.5,2.54,5.6,0.97,4.65}; floaty[]={-6,4.3,4.5,3.67,2.42,2.54,5.6,-0.97,4.65,-3.33}; // 此处起要求考生自己编制程序 p=fopen("design.dat","w"); for(i=0;i<10;i++) if(((x[i]-1)*(x[i]-1)+(y[i]+0.5)*(y[i]+0.5)<=25)&& ((x[i]-0.5)*(x[i]-0.5)+(y[i]*y[i])<=36)) k++; fprintf(p,"%d",k); // 答案: 3 fclose(p); } 7. 程序设计题: 数组元素x[i]、y[i]表示平面上某点坐标,统计所有各点间最短距离,并将其值以格式"%f"写到考生目录下新建文件design.dat。 #include #include #definelen(x1,y1,x2,y2)sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) voidmain() { FILE*p;inti,j;floatc,minc; floatx[]={1.1,3.2,-2.5,5.67,3.42,-4.5,2.54,5.6,0.97,4.65}; floaty[]={-6,4.3,4.5,3.67,2.42,2.54,5.6,-0.97,4.65,-3.33}; minc=len(x[0],y[0],x[1],y[1]); // 此处起要求考生自己编制程序 p=fopen("design.dat","w"); for(i=0;i<9;i++) for(j=i+1;j<10;j++) if((c=len(x[i],y[i],x[j],y[j])) minc=c; fprintf(p,"%f",minc); // 答案: 1.457944 fclose(p); } 8. 程序设计题: 将数组a的每一行均除以该行上的主对角元素(第1行同除以a[0][0],第2行同除以a[1][1],...,)然后将a数组写入到考生目录下新建的文件design.dat. #include #include voidmain() { floata[3][3]={{1.3,2.7,3.6},{2,3,4.7},{3,4,1.27}}; FILE*p;inti,j; // 此处起要求考生自己编制程序 float k; if((p=fopen("design.dat","w"))==NULL) { printf("cannotopeninFILE\n"); exit(0); } for(i=0;i<3;i++) { k=a[i][i]; for(j=0;j<3;j++) a[i][j]=a[i][j]/k; } // 此处起要求考生自己编制程序 for(i=0;i<3;i++){ for(j=0;j<3;j++)fprintf(p,"%10.6f",a[i][j]); // 答案: 1.000000 2.076923 2.769231 fprintf(p,"\n"); // 0.666667 1.000000 1.566667 } // 2.362205 3.149606 1.000000 fclose(p); } 9. 程序设计题: 计算表达式1+2! +3! +...+12! 的值,并将计算结果以格式"%d"写入到考生目录下新建的文件design.dat。 #include #include voidmain() { FILE*p;ints=1,k=1,i; // 此处起要求考生自己编制程序 if((p=fopen("design.dat","w"))==NULL) { printf("cannotopeninFILE\n"); exit(0); } for(i=2;i<=12;i++) { k*=i;s+=k; } fprintf(p,"%d",s); // 答案: 522956313 fclose(p); } 10. 程序设计题: 在6至1000内找出所有的合数,并顺序将每个合数用语句“fprintf(p,"%6d",n)”写入到考生目录下新建的文件design.dat。 说明: 某数等于其诸因子之和则该数为合数,如6=1+2+3,28=1+2+4+7+14则 6、28就是合数。 #include #include voidmain() { FILE*p; intn,i,s; // 此处起要求考生自己编制程序 if((p=fopen("design.dat","w"))==NULL) { printf("cannotopeninFILE\n"); exit(0); } for(n=6;n<=1000;n++) { s=0; for(i=1;i if(n%i==0)s+=i; if(n==s)fprintf(p,"%6d",n); // 答案: 6 28 496 } fclose(p); } 11. 程序设计题: 在正整数中找出一个最小的、被3、5、7、9除余数分别为1、3、5、7的数,将该数以格式"%d"写到考生目录下新建文件design.dat。 #include #include voidmain() { // 此处起要求考生自己编制程序 FILE*p;inti; if((p=fopen("design.dat","w"))==NULL) { printf("cannotopenFILE"); exit(0);} for(i=1;;i++) if(i%3==1&&i%5==3&&i%7==5&&i%9==7)break; fprintf(p,"%d",i); fclose(p); } // 答案: 313 12.程序设计题: a、b、c为区间[1,100]的整数,统计使等式c/(a*a+b*b)=1成立的所有解的个数,并将统计数以格式"%d"写入到考生目录下新建文件design.dat(若a=1、b=3、c=10是1个解,则a=3、b=1、c=10也是解) #include voidmain() { FILE*p;intn=0,a,b,c; // 此处起要求考生自己编制程序 if((p=fopen("design.dat","w"))==NULL) { printf("cannotopeninFILE\n"); exit(0); } for(a=1;a<=100;a++) for(b=1;b<=100;b++) for(c=1;c<=100;c++) if((a*a+b*b)==c) // 同学们注意: 若写成c/(a*a+b*b)==1就上当了! n+=1; // 想一想为什么? fprintf(p,"%d",n); // 答案: 69个 fclose(p); } 13. 程序设计题: 对x=1,2,...,10,求函数f(x)=x-10*cos(x)+5*sin(x)的最大值,并将该数以格式 "%.2f"写到考生目录下新建文件design.dat。 #include #include #include voidmain() { FILE*p;floatf(float),max; intx; // 此处起要求考生自己编制程序 if((p=fopen("design.dat","w"))==NULL) { printf("cannotopenfile\n"); exit(0); } max=f (1); for(x=2;x<=10;x++) if(max max=f(x); fprintf(p,"%.2f",max); // 答案: 20.17 fclose(p); } floatf(floatx) { x=x-10*cos(x)+5*sin(x); returnx; } 14. 程序设计题: 统计满足条件x*x+y*y+z*z==2000的所有解的个数,并将统计结果以格式"%d"写入到考生目录下新建的文件design.dat。 说明: 若a、b、c是一个解,则a、c、b也是一个解,等等。 #include voidmain() { FILE*p;intx,y,z,k=0; // 此处起要求考生自己编制程序 if((p=fopen("design.dat","w"))==NULL) { printf("cannotopenFILE"); exit(0); } for(x=-45;x<45;x++) for(y=-45;y<45;y++) for(z=-45;z<45;z++) if(x*x+y*y+z*z==2000)k++; // 该题有x,y,z 取值范围的问题! fprintf(p,"%d",k); // 答案: 144 fclose(p); } 15. 程序设计题: 在6至5000内找出所有的亲密数对,并将每对亲密数用语句“fprintf(p,"%6d,%6d\n",a,b);”写到考生目录下新建文件design.dat。 说明: 若a、b为一对亲密数,则a的因子和等于b、b的因子和等于a、且a不等于b。 如: 220、284是一对亲密数,284、220也是一对亲密数。 #include voidmain() { FILE*p; inti,a,b,c; p=fopen("design.dat","w"); printf("程序正在运行,请稍等....\n"); for(a=6;a<=5000;a++) { // 此处起要求考生自己编制程序 */ b=c=0;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 二级