欢迎来到天天文库
浏览记录
ID:51401647
大小:1.19 MB
页数:20页
时间:2020-03-23
《安徽省二级c语言上机试题.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1:改错:输出小于2012的最大10个素数,如2011,2003,1999,1997,1993………等。#includevoidmain(){inti,j,flag,n;n=0;i=2012;while(n<=10)/*$ERROR1$*/{flag=0;for(j=2;j=0)/*$ERROR3$*/{n=n+1;printf("%d",i);}i=i-1;}}答案:While(n<10)If(i%j==0)If(flag==0
2、)2:程序填空:将在字符串t中而为在字符串s中的字符顺序存放到一个新的字符u中。如当s=12345,t=2468时,u中的字符为“68”#include#includevoidmain(){chars[80]="12345",t[80]="2468",u[80];inti,j,p,len1,len2;p=____;/*$BLANK1$*/len1=strlen(t);len2=strlen(s);for(i=0;i3、(j>=len2){u[p]=____;/*$BLANK2$*/p++;}}u[p]=____;/*$BLANK3$*/printf("%s",u);}答案:0t[i] 3:程序设计:[三色球问题]若一个口袋中方有12的球,3的红色,3的白色,6个黑色。从中任取8个球,求共有多少种不同的颜色搭配。如1红,3白,4黑。等。输入格式:count=123#includevoidPRINT(intn){FILE*out;printf("count=%d",n);if((out=fopen("K:\24000101\RESULT.D4、AT","w+"))!=NULL)fprintf(out,"count=%dp",n);fclose(out);}voidmain(){intr,w,b;intn=0;for(r=0;r<=3;r++)for(w=0,w<=3,w++)for(b=0;b<=6;b++)if(r+w+b==8)n++;PRINT(n);}1:改错#includevoidmain(){inti,j;i=1;while(i<6){for(j=1;j<6-i;j++)printf("");j=1;/*$ERROR1$*/while(j>=1){printf("5、%d",i);/*$ERROR2$*/--j;}printf("/n");/*$ERROR3$*/i++;}}答案:J=I;Printf(“%d”,j)Printf(“”)2:程序填空#includefloatsum(floatq){intN=1;floatSN=0;while(SN__q)/*$BLANK1$*/{SN=SN+1.0*(N+1)/N;____;/*$BLANK2$*/}returnSN;}voidmain(){floatq;printf("Inputq:");scanf("%f",&q);printf("%f"6、,_____);/*$BLANK3$*/}答案:<=N++sum(q))3程序设计#includevoidPRINT(longsum){FILE*out;printf("sum=%ld",sum);if((out=fopen("K:\24000101\RESULT.DAT","w+"))!=NULL)fprintf(out,"sum=%lds",sum);fclose(out);}voidmain(){Iongsum=0;intI,n,flag;for(i=100;i<2011;i++){flag=0;n=i;do{if(n%17、0==5){flag=1;break;}elsen=n/10;}while(n>0);if(flag&&i%3==0)sum+=i}PRINT(sum);}1:改错#include#defineN4#defineM5voidmain(){inti,j;floatscore,firstscore,max;for(i=1;i<=M;i++){printf("Pleaseinputscoreofcourseno%d:",i);scanf("%f",firstscore);/*$ERROR1$*/max=&firstscore;/*$ERR8、OR2$*/for(j=2;j<=N;j++){scanf("%f",&scor
3、(j>=len2){u[p]=____;/*$BLANK2$*/p++;}}u[p]=____;/*$BLANK3$*/printf("%s",u);}答案:0t[i] 3:程序设计:[三色球问题]若一个口袋中方有12的球,3的红色,3的白色,6个黑色。从中任取8个球,求共有多少种不同的颜色搭配。如1红,3白,4黑。等。输入格式:count=123#includevoidPRINT(intn){FILE*out;printf("count=%d",n);if((out=fopen("K:\24000101\RESULT.D
4、AT","w+"))!=NULL)fprintf(out,"count=%dp",n);fclose(out);}voidmain(){intr,w,b;intn=0;for(r=0;r<=3;r++)for(w=0,w<=3,w++)for(b=0;b<=6;b++)if(r+w+b==8)n++;PRINT(n);}1:改错#includevoidmain(){inti,j;i=1;while(i<6){for(j=1;j<6-i;j++)printf("");j=1;/*$ERROR1$*/while(j>=1){printf("
5、%d",i);/*$ERROR2$*/--j;}printf("/n");/*$ERROR3$*/i++;}}答案:J=I;Printf(“%d”,j)Printf(“”)2:程序填空#includefloatsum(floatq){intN=1;floatSN=0;while(SN__q)/*$BLANK1$*/{SN=SN+1.0*(N+1)/N;____;/*$BLANK2$*/}returnSN;}voidmain(){floatq;printf("Inputq:");scanf("%f",&q);printf("%f"
6、,_____);/*$BLANK3$*/}答案:<=N++sum(q))3程序设计#includevoidPRINT(longsum){FILE*out;printf("sum=%ld",sum);if((out=fopen("K:\24000101\RESULT.DAT","w+"))!=NULL)fprintf(out,"sum=%lds",sum);fclose(out);}voidmain(){Iongsum=0;intI,n,flag;for(i=100;i<2011;i++){flag=0;n=i;do{if(n%1
7、0==5){flag=1;break;}elsen=n/10;}while(n>0);if(flag&&i%3==0)sum+=i}PRINT(sum);}1:改错#include#defineN4#defineM5voidmain(){inti,j;floatscore,firstscore,max;for(i=1;i<=M;i++){printf("Pleaseinputscoreofcourseno%d:",i);scanf("%f",firstscore);/*$ERROR1$*/max=&firstscore;/*$ERR
8、OR2$*/for(j=2;j<=N;j++){scanf("%f",&scor
此文档下载收益归作者所有