- 2022-04-09 发布 |
- 37.5 KB |
- 18页
申明敬告: 本站不保证该用户上传的文档完整性,不预览、不比对内容而直接下载产生的反悔问题本站不予受理。
文档介绍
!!!最新2009年12月C语言大题参考答案
2009年12月C语言程序设计等级考试大题参考答案一、改错题#include
voidmain(){inta,b,c;/**/intf;/**/改为:floatf;clrscr();printf("Pleaseinputab:");scanf("%d%d",/**/a,b/**/);改为:&a,&bf=/**/a/b;/**/改为:(float)a/b;或1.0*a/b;c=(int)((f-(int)f)*10);printf("n%f%dn",f,c);getch();}#includevoidfind(/**/n/**/)改为:intn{inta1,a2;a1=m%10;a2=m/10;if(m%3==0&&(/**/a1==4&&a2==4/**/))改为:a1==4||a2==4printf("%dn",m);}voidmain(){intk;for(k=10;k<=99;k++)/**/fun(k)/**/;改为:find(k)getch();}#includevoidmain(){/**/inta,Tag;/**/改为:inta,tag;intnum1=0,num2=0;clrscr();printf("pleaseinputnumbers:");scanf("%d",/**/a/**/);改为:&atag=a;while(a){scanf("%d",&a);n/**/if(a)/**/continue;改为:if(a==0)elseif(atag)num2++;}printf("n%d%dn",num1,num2);getch();}#includelongintfsum(intn){longintk;if(n==1)/**/k=0/**/;改为:k=1elsek=n*fsum(n-1);return(/**/1/**/);改为:k}voidmain(){inti;longintsum;sum=0;for(i=1;i<=9;/**/i++;i++/**/)改为:i++,i++或i=i+2sum+=fsum(i);printf("sum=%ldn",sum);getch();}#includevoidmain(){inti,a=0;/**/c1,c2;/**/改为:charc1,c2;clrscr();printf("Enteran8bitbinarynumber:");c2=getchar();/**/for(i=1,i<=7;i++)/**/改为:for(i=1;i<=7;i++){c1=getchar();a=a*2+c1-'0';}/**/If(c2)/**/a=(-1)*a;改为:if(c2)printf("n%dn",a);getch();}n#includevoidmain(){inti,n;/**/n=1;/**/改为:n=0for(i=10;i<=100;i++)if(i/10==i%10){printf("%5d",i);n++;if(/**/n%9=0/**/)改为:n%9==0printf("n");}for(i=100;i<=999;i++)if(/**/i/100==i/10/**/)改为:i/100==i%10{printf("%5d",i);n++;if(n%9==0)printf("n");}getch();}#includevoidmain(){/**/inta(10);/**/改为:inta[10];inti,j,k,x;printf("Enter10numbers:");scanf("%d",/**/x/**/);改为:&xa[0]=x;for(k=1;k<=9;k++){scanf("%d",&x);for(i=0;ix)break;if(ii;j--)a[j]=a[j-1];a[i]=x;}/**/for(i=1;i<=10;i++)/**/改为:for(i=0;i<=9;i++)printf("%d",a[i]);printf("n");getch();}n#include#includeintfun(/**/floata,b,c/**/)改为:floata,floatb,floatc{floatt;intmk=0;if(cvoidmain(){inta[10]={0};/**/inti,j,k,temp,/**/改为:inti,j,k,temp;printf("Enter10numbers:");/**/for(k=1;k<10;k++)/**/改为:for(k=0;k<10;k++)scanf("%d",&a[k]);for(i=0;i<9;i++){k=i;for(j=i+1;j<10;j++){if(a[k]>a[j])k=j;}if(k!=i)/**/{temp=a[i];a[k]=a[i];a[i]=temp;}/**/改为:{temp=a[k];a[k]=a[i];a[i]=temp;}}for(i=0;i<10;i++)printf("%d",a[i]);printf("n");getch();n}#includevoidmain(){floata,b,c,max;floatfmax(float,float,float);printf("Pleaseinput3numbers:n");scanf("%f%f%f",&a,&b,&c);max=/**/fmax(a;b;c)/**/;改为:fmax(a,b,c)printf("Themaxnumberis:%.2fn",max);getch();}/**/floatfmax(floatx,y,z)/**/改为:floatfmax(floatx,floaty,floatz){floatm1,m2;m1=(y>z)?y:z;m2=/**/(x>y)?x:y;/**/改为:(x>m1)?x:m1;return(m2);}#includevoidmain(){inta[20]={1,3,7,9,12,14,23,26,34,43,45,47,49,56,58,59,78,79,87,89};intleft,right,mid,q,count;left=0;/**/right=19/**/改为:right=19;printf("pleaseinputanumber:");scanf("%d",/**/q/**/);改为:&qcount=1;while(left<=right){mid=(left+right)/2;if(q==a[mid])break;elseif(q#includeintfun(/**/floatr,x,y/**/)改为:floatr,floatx,floaty{if(sqrt(x*x+y*y)0):n");scanf("%f",&r);}printf("Pleaseinputthedot(x,y):n");scanf("%f%f",&x,&y);bIn=fun(r,x,y);if(/**/bIn=0/**/)改为:bIn!=0或bIn==1printf("inthecircle!n");elseprintf("outoftheCircle!n");getch();}二、填空题#include#includevoidmain(){/**/int/**/a,b,temp;scanf("%d,%d",&a,&b);if(ab)/**/{if(a%3==0)printf("%d",a);}printf("n");ngetch();}#includedoublefun(/**/intn/**/){doubley=0.0;inti,j;for(i=1;i<=n;i++){y=y+/**/1.0/(8+3*i)/**/;}return(/**/y/**/);}voidmain(){clrscr();printf("fun(7)=%8.3lfn",fun(7));getch();}#includevoidmain(){intm,n;for(m=1;/**/m<=5;/**/m++){printf("n");for(n=1;n<=/**/m-1;/**/n++)printf(/**/““/**/);for(n=9;n>=m*2-1;n--)printf("*");}getch();}#includemain(){voidfun(int);intv=300;nfun(/**/v/**/);getch();}voidfun(intm){intc1,c2;for(c1=1;/**/c1<=30;/**/;c1++){for(c2=1;c2<=15;c2++)if(c1*10+c2*20==/**/m/**/)printf("c1=%d,c2=%dn",c1,c2);}}#include#includevoidmain(){intnum1,num2,ans,flag;charop;clrscr();printf("Pleaseinputanexpression:");scanf("%d%c%d",/**/&num1,&op,&num2/**/);flag=0;/**/switch(op)/**/{case'+':ans=num1+num2;break;case'-':ans=num1-num2;break;case'*':ans=num1*num2;break;case'/':ans=num1/num2;break;default:{printf("Error!n");flag=1;}}if/**/(flag==0)/**/printf("%d%c%d=%dn",num1,op,num2,ans);getch();}#include#includevoidmain(){charsrc[40],tag[40];nvoidch_pw();printf("Pleaseinputastring:");gets(src);strcpy(tag,src);ch_pw(tag);printf("nThesourcestring:%sn",src);printf("nThetargetstring:%sn",tag);getch();}voidch_pw(/**/charstr[]/**/){chartab[4][2]={{'a','d'},{'s','f'},{'d','a'},{'f','s'}};intj=0,i;while(str[j]){for(i=0;i<=3;i++){if(str[j]==tab[i][0]){/**/str[j]/**/=tab[i][1];break;}}/**/j++;/**/;}}#include#includevoidmain(){charstr[80];charc;inti;/**/i=0;/**/printf("nPleaseinputthestring:");while((c=getchar())!='n'){if(c>='A'&&c<='Z'||c>='a'&&c<='z')/**/str[i++]=c;/**/}str[i]=/**/0;(或者:’ ’;)/**/puts(str);getch();}n#include#include#defineN9voidivs(inta[]){inti,temp;for(i=0;/**/i#includevoidmain(){/**/char/**/str[80];inti,len,sum=0;printf("nPleaseinputthestring:");gets(str);len=strlen(str);for(i=0;i='A'&&str[i]<='Z'||str[i]>='a'&&str[i]<='z')/**/continue;/**/else/**/sum++;/**/}printf("%dn",sum);getch();}n#include#includevoidmain(){inthcf(int,int);inta,b,k;printf("Enterab:");scanf("%d%d",&a,&b);k=hcf(/**/a,b/**/);printf("H.C.F=%dn",k);getch();}inthcf(intx,inty){intr;r=x%y;while(r!=0){x=y;y=/**/r/**/;r=x%y;}return(/**/y/**/);}#include#includevoidmain(){chars1[100],s2[100];inti,len;printf("Pleaseinputstring:n");gets(s1);len=strlen(s1);for(i=0;i='1'&&s1[i]<='9')/**/s2[i]=s1[i]-1;/**/elseif(s1[i]=='0')/**/s2[i]=’9’;/**/elses2[i]=s1[i];}ns2[i]=/**/0(或者:’ ’)/**/;puts(s2);getch();}#include#includevoidsct(chars1[],/**/chars2[]/**/){char*p1,*p2;p1=/**/s1/**/;p2=s2;while(*p1)p1++;while(*p2)*(p1++)=*(p2++);}voidmain(){charstr1[60]="Nothing",str2[]="final";sct(/**/str1/**/,str2);printf("n%sn",str1);getch();}三、编程题#include#includedoublefunc(doublex){/**/doubley;y=(3*x*sin(x)+tan(x))/(1.5+fabs(x));returny;/**/}voidmain(){clrscr();printf("func(0.26)=%6.3lfn",func(0.26));printf("func(5.00)=%6.3lfn",func(5.00));printf("func(8.50)=%6.3lfn",func(8.50));getch();}n#includeintfun(inta[],intn,float*f){/**/inti,t=0;for(i=0;i*f)t++;returnt;/**/}voidmain(){inta[]={23,40,8,32,18,2,9,16,27};inti,k=sizeof(a)/sizeof(int);intcount=0;floataver=0.0;printf("Arraya:n");for(i=0;i#includedoublefunc(doublex){/**/doubley;y=(exp(x)+sin(x-6))/(x*x+1);returny;/**/}voidmain(){clrscr();printf("func(0.26)=%6.3lfn",func(0.26));printf("func(5.00)=%6.3lfn",func(5.00));printf("func(8.50)=%6.3lfn",func(8.50));getch();}#include#includeintfind(inta[],intn,floatx){/**/inti,t;floatmin=fabs(x-a[0]);nfor(i=1;i#includedoublefun1(floatx){/**/doubley;if(x<3)y=sin(x);elseif(x==3)y=x;elsey=cos(2*x+1);returny;/**/}voidmain(){floatx;doubley;clrscr();printf("Pleaseinputanumber:n");scanf("%f",&x);y=fun1(x);printf("fun1(%.2f)=%.2fn",x,y);getch();}n#include#includeintfun(intbg,intfn){/**/inti,j,t=0;for(i=bg;i<=fn;i++){for(j=2;j=i/2)t++;}returnt;/**/}voidmain(){intcount;count=fun(100,500);printf("nThetotalofprimeis%d",count);getch();}#include#includedoublefun1(floatx){/**/doubley;if(x<3)y=pow(2.5+fabs(x),1.0/3)/(sin(x)+3);elsey=x;returny;/**/}voidmain(){floatx;doubley;clrscr();printf("Pleaseinputanumber:n");scanf("%f",&x);y=fun1(x);printf("fun1(%.2f)=%.2fn",x,y);getch();}n#includedoublefun(intn){/**/inti;doublek=1.0,s=0;for(i=1;i<=n;i++){s+=k/(i*(2*i+1));k=-k;}returns;/**/}voidmain(){intn;printf("Inputn:");scanf("%d",&n);printf("fun(%d)=%lfn",n,fun(n));getch();}#include#includedoublefun1(floatx){/**/doubley;if(x<10)y=sqrt(2.5+cos(x))/(x*sin(x)+3);elsey=x*x;returny;/**/}voidmain(){floatx;doubley;clrscr();printf("Pleaseinputanumber:n");scanf("%f",&x);y=fun1(x);printf("fun1(%.2f)=%.2fn",x,y);getch();}n#include#includeintbTrue(inta[][4],intn){/**/inti,j,t=1;for(i=0;i#includedoublefun1(floatx){/**/doubley;if(x<100)y=(3*log10(x)-3)/(sin(x)+3);elsey=x-100;returny;/**/}voidmain(){floatx;doubley;nclrscr();printf("Pleaseinputanumber:n");scanf("%f",&x);y=fun1(x);printf("fun1(%.2f)=%.2fn",x,y);getch();}#include#includeintfun(inta[],intn){/**/inti,t=a[0];floatavg=0,max;for(i=0;imax){max=fabs(a[i]-avg);t=a[i];}returnt;/**/}voidmain(){inta[]={10,22,8,33,17,5,9,13,27};inti,n=sizeof(a)/sizeof(int);intk;printf("Arraya:n");for(i=0;i
查看更多
!!!最新2009年12月C语言大题参考答案
文档大小:245.50 KB 文档价格:
!!!最新2009年12月C语言大题参考答案
文档大小:245.50 KB 文档价格:
关闭