资源描述:
《电大《c语言程序设计》期末复习资料(3)》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、复习资料(1620)三、写出程序运行结果1.#includestdio.hvoidmain{intiJ,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){x/=i;}i++;}}结果:251.#includcstdio.hvoidmain{inta[8]={76,63,54,95,40,75,90,66};inti,s=0;for(i=0;i8;i++)if(a[i]=70a[i]=90)
2、s+=a[i];printf(us=%d/n,,,s);}结果:2412.#includestdio.hintWF(intx,inty){x=x+y;y+=x;returnx+y;}voidmain{printf(“%d/iT,WF(x,y));1.#includestdio.hvoidmain{intx=5;switch(2*x-1){case4:printf(<4%d",x);break;case7:printf(u%d“,2*x);break;case10:printf(<4%d“,3*x);break;default:printfC'^s"‘''defa
3、ult'');1printf("%s/n,,,,,switchend.,?);}结果:defaultswitchend.2.#includcstdio.hvoidmain{intfl,f2,i;fl=l;printf(t<%d“,fl);f2=3*fl+l;fl=f2;printf(<7n^^);}结果:1413401211.#includestdio.hvoidmain{inta[10]={12,39,26,41,55,63,72,40,83,95};inti,il=0,i2=0;for(i=0;i10;i++)if(a[i]%2==l)il++;elsei2
4、++;printf(“%d%d/n”,i1,i2);}结果:642.#includcstdio.h#includestring・hvoidmain(){chars[15]=“567891234";inti,n=strlen(s);charc=s[ij;s[i]=s[n-1-i];s[n-1-ij=c;printf(“%s/n",s);}结果:4321987659・#includestdio.hintLB(int*a,intn){inti,s二1;for(i=0;in;i++)s*=*a++;returns;)voidmain{inta[]={1,2,3,4,2,
5、4,5,2};intb二LB(a,4)+LB(a+3,3);printf(ub=%d/n,,,b);)结果:b=5610.#includestdio.hvoidmain{inti,s=0;for(i=l;i6;i++)s+=i*i;结果:s=5511.#includestdio.h#defineN6voidmain{inti,a[N]={2,5,8,10,15,21);for(i=0;iN;i++)if(afi]%5)printf(**%d“,a⑴);printf(<7n,>);1结果:282112.#includestdio.h#includestring.h
6、voidmain{inti;unsignedintlen;char*a[5]={^studcnt^/^orkcr^/^adre^/^oldicr^/^zcasan123"};len=strlen(a[OJ);for(i=l;i5;i++)if(strlen(a[i])len)len=strlen(a[i]);结果:1013.#includestdio.hvoidmain{inta,b;for(a=2,b=3;b20;){printf(u%d%d“,a,b);a=a+b;b=a+b;)printf(u%d%d/n",a,b);)结果:2358132114.#inc
7、ludcstdio.hvoidLE(int*a,int*b){intx=*a;*a=*b;*b=x;}voidmain{intx=15,y=26;LE(x,y);printf(u%d%d/n",x,y);结果:1526261I5.#includestdio.hvoid}结果:s=4216.#includestdio.hvoidmain{inti,s=0;for(i=1;;i++){if(s3O)break;if(i%2==0)s+=i;)printf(us=%d/n,,,s);main{inta[9]={36,25,48,24,55,40,18,66,20};i
8、nti,bl,b2;b1