资源描述:
《本科电大《c语言程序设计a》复习资料2》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、复习资料(1620)三、写出下列每个程序运行后的输出结果1•#includestdio.hvoidmain{inti,j,k=O;for(i=0;i5;i++)for(j=i;j5;j++)k++;;printf(“%d/n",k);}运行结果:152.#includestdio.hvoidmain{intx=20;inti=2;while(ix){if(x%i==0){printf(u%d“,i);x/=i;}i++;)13.#includestdio.hvoidmain{inta[8]={70,63,54,95,40,75,90,66};
2、inti,s=0;for(i=0;i8;i++)if(a[i]=70a[i]=90)s+=a[i];printf(us=%d/n,,,s);}运行结果:s=2354・#includestdio.hintWF(intx,inty){x=x+y;y+二x;returnx+y;}voidmain{intx=3,y=5;printf(<<%d/n,,,WF(x,y));}运行结果:21intLA(int*a,intn){inti,s=O;for(i=0;in;i++)s+=a[i];returns;)voidmain{inta[5]={l,2,3,4
3、,5};intb=LA(a,5)+LA(a+1,3);printf(ttb=%d/n,b);)运行结果:b=246.#includestdio.hvoidmain{intx=5;switch(2*x-l){case4:printf(“%d",x);break;case7:printf(4t%d“,2*x);break;case10:printf(u%d",3*x);break;default:printf(“%sdefault”);printf("%s/n'',"switchend.");}运行结果:defaultswitchend.fl=
4、l;printf(4t%d“,fl);for(i=2;i=5;i++){f2=3*fl+l;printf(u%d“,f2);fl=f2;}pi'intf(“/n“);}运行结果:1413401218.#includestdio.hvoidmain{inta[10]={12,39,26,41,55,63,72,40,83,95};inti,i1=0,i2=0;for(i=0;i10;i++)if(a[i]%2==1)i1++;elsei2++;printf(“%d%d/n,,,i1,i2);}运行结果:649.#includestdio.h#i
5、ncludestring.hchars[15]=“567891234”;inti,n=strlen(s);for(i=0;in/2;i++){charc=s[i];s[i]=s[n-l-i];s[n-1-i]=c;}printf(u%s/n,,,s);运行结果:4321987651()・#incluclestdio.hintLB(int*a,intn){inti,s=1;for(i=0;in;i++)s*=*a++;returns;}voidmain{inta[]={l,2,3,4,2,4,5,2};intb=LB(a,4)+LB(a+3,3
6、);printf(ttb=%d/n,,,b);)运行结果:b=56inti,s=0;for(i=1;;i++){if(s30)break;if(i%2==0)s+=i;}printf(tts=%d/n,,,s);}运行结果:s=4212.#includestdio.hvoidmain{inta[91={36,25,48,24,55,40,18,66,20};inti,b1,b2;bl=b2=a[0];for(i=1;i9;i++){if(a[订bl)bl=a[i];if(a[订b2)b2=a[订;}printf(4t%d%d/n,,,bl,b
7、2);}运彳丁结果:661813.#includestdio.hvoidSB(charch){switch(ch){case'A':case'a':printf(4tWW“);break;case'B':case'b':printf(“GG“);break;default:printf(uBB“);break;}voidmain{chara1='a',a2='B',a3='f';SB(al);SB(a2);SB(a3);printf(t7n,,)i}运行结果:WWGGBB14.#includestdio.h#defineM6voidmain{
8、inti,x;inta[M]={10,15,22,37,46,58};for(i=0;iM/2;i++){x=a[i];a[il=a[M-l-i];a[M-l-i]