欢迎来到天天文库
浏览记录
ID:59007219
大小:31.00 KB
页数:6页
时间:2020-09-15
《C程序分析练习题.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、C++程序设计练习题(1~5章)写出程序的运行结果 3.#includeconstintM=3,N=4;voidmain(){inti,j,s=0;for(i=1;i<=M;i++)for(j=1;j<=N;j++)s+=i*j;cout<<”s=”<voidmain(){inta=2,b=5,c=0;if(a+b>10)c=a*b;elsec=3*a+b;if(c<=20)cout<2、+c-5;cout<voidmain(){intx=5;switch(2*x-3){case4:cout<3、} 6.#include#includeinta[4]={36,-5,73,8};voidmain(){inti,y;for(i=0;i<4;i++){if(a[i]<0)y=1;elseif(a[i]<10)y=a[i]*a[i]+3;elseif(a[i]<60)y=4*a[i]-5;elsey=int(sqrt(a[i]));//sqrt(x)为取x的平方根函数cout<4、m.h>inta[8]={36,25,20,43,12,70,66,35};voidmain(){ints0,s1,s2;s0=s1=s2=0;for(inti=0;i<8;i++){switch(a[i]%3){case0:s0+=a[i];break;case1:s1+=a[i];break;case2:s2+=a[i];break;}}cout<constintN=5;voidmain(){inti,p=5、1,s=0;for(i=1;iconstintM=20;voidmain(){intc2,c3,c5;c2=c3=c5=0;for(inti=1;i<=M;i++){if(i%2==0)c2++;if(i%3==0)c3++;if(i%5==0)c5++;}cout<6、} 10.#includevoidmain(){inti,j;for(i=0;i<5;i++){for(j=i;j<5;j++)cout<<’*’;cout<voidmain(){for(inti=1,s=0;i<20;i++){if(i%2==07、8、i%3==0)continue;cout<constintT=6;9、voidmain(){inti,j;for(i=1;i<=T;i+=2)for(j=2;j<=T;j+=2){if(i+jvoidmain(){inta,b,c=0;for(a=1;a<4;a++)for(b=6;b>1;b-=2){if((a+b)%2==0)c+=a+b;elsec+=a*b;if(b==2)cout<10、stream.h>constintB=2;voidmain(){intp=1,s=1;while(s<50){p*=B;s+=p;}cout<<"s="<voidmain(){intx=24,y=88;inti=2,p=1;do{while(x%i==0&&y%i==0){p*=i;x/=i;y/=i;}i++;}while(x>
2、+c-5;cout<voidmain(){intx=5;switch(2*x-3){case4:cout<3、} 6.#include#includeinta[4]={36,-5,73,8};voidmain(){inti,y;for(i=0;i<4;i++){if(a[i]<0)y=1;elseif(a[i]<10)y=a[i]*a[i]+3;elseif(a[i]<60)y=4*a[i]-5;elsey=int(sqrt(a[i]));//sqrt(x)为取x的平方根函数cout<4、m.h>inta[8]={36,25,20,43,12,70,66,35};voidmain(){ints0,s1,s2;s0=s1=s2=0;for(inti=0;i<8;i++){switch(a[i]%3){case0:s0+=a[i];break;case1:s1+=a[i];break;case2:s2+=a[i];break;}}cout<constintN=5;voidmain(){inti,p=5、1,s=0;for(i=1;iconstintM=20;voidmain(){intc2,c3,c5;c2=c3=c5=0;for(inti=1;i<=M;i++){if(i%2==0)c2++;if(i%3==0)c3++;if(i%5==0)c5++;}cout<6、} 10.#includevoidmain(){inti,j;for(i=0;i<5;i++){for(j=i;j<5;j++)cout<<’*’;cout<voidmain(){for(inti=1,s=0;i<20;i++){if(i%2==07、8、i%3==0)continue;cout<constintT=6;9、voidmain(){inti,j;for(i=1;i<=T;i+=2)for(j=2;j<=T;j+=2){if(i+jvoidmain(){inta,b,c=0;for(a=1;a<4;a++)for(b=6;b>1;b-=2){if((a+b)%2==0)c+=a+b;elsec+=a*b;if(b==2)cout<10、stream.h>constintB=2;voidmain(){intp=1,s=1;while(s<50){p*=B;s+=p;}cout<<"s="<voidmain(){intx=24,y=88;inti=2,p=1;do{while(x%i==0&&y%i==0){p*=i;x/=i;y/=i;}i++;}while(x>
3、} 6.#include#includeinta[4]={36,-5,73,8};voidmain(){inti,y;for(i=0;i<4;i++){if(a[i]<0)y=1;elseif(a[i]<10)y=a[i]*a[i]+3;elseif(a[i]<60)y=4*a[i]-5;elsey=int(sqrt(a[i]));//sqrt(x)为取x的平方根函数cout<4、m.h>inta[8]={36,25,20,43,12,70,66,35};voidmain(){ints0,s1,s2;s0=s1=s2=0;for(inti=0;i<8;i++){switch(a[i]%3){case0:s0+=a[i];break;case1:s1+=a[i];break;case2:s2+=a[i];break;}}cout<constintN=5;voidmain(){inti,p=5、1,s=0;for(i=1;iconstintM=20;voidmain(){intc2,c3,c5;c2=c3=c5=0;for(inti=1;i<=M;i++){if(i%2==0)c2++;if(i%3==0)c3++;if(i%5==0)c5++;}cout<6、} 10.#includevoidmain(){inti,j;for(i=0;i<5;i++){for(j=i;j<5;j++)cout<<’*’;cout<voidmain(){for(inti=1,s=0;i<20;i++){if(i%2==07、8、i%3==0)continue;cout<constintT=6;9、voidmain(){inti,j;for(i=1;i<=T;i+=2)for(j=2;j<=T;j+=2){if(i+jvoidmain(){inta,b,c=0;for(a=1;a<4;a++)for(b=6;b>1;b-=2){if((a+b)%2==0)c+=a+b;elsec+=a*b;if(b==2)cout<10、stream.h>constintB=2;voidmain(){intp=1,s=1;while(s<50){p*=B;s+=p;}cout<<"s="<voidmain(){intx=24,y=88;inti=2,p=1;do{while(x%i==0&&y%i==0){p*=i;x/=i;y/=i;}i++;}while(x>
4、m.h>inta[8]={36,25,20,43,12,70,66,35};voidmain(){ints0,s1,s2;s0=s1=s2=0;for(inti=0;i<8;i++){switch(a[i]%3){case0:s0+=a[i];break;case1:s1+=a[i];break;case2:s2+=a[i];break;}}cout<constintN=5;voidmain(){inti,p=
5、1,s=0;for(i=1;iconstintM=20;voidmain(){intc2,c3,c5;c2=c3=c5=0;for(inti=1;i<=M;i++){if(i%2==0)c2++;if(i%3==0)c3++;if(i%5==0)c5++;}cout<6、} 10.#includevoidmain(){inti,j;for(i=0;i<5;i++){for(j=i;j<5;j++)cout<<’*’;cout<voidmain(){for(inti=1,s=0;i<20;i++){if(i%2==07、8、i%3==0)continue;cout<constintT=6;9、voidmain(){inti,j;for(i=1;i<=T;i+=2)for(j=2;j<=T;j+=2){if(i+jvoidmain(){inta,b,c=0;for(a=1;a<4;a++)for(b=6;b>1;b-=2){if((a+b)%2==0)c+=a+b;elsec+=a*b;if(b==2)cout<10、stream.h>constintB=2;voidmain(){intp=1,s=1;while(s<50){p*=B;s+=p;}cout<<"s="<voidmain(){intx=24,y=88;inti=2,p=1;do{while(x%i==0&&y%i==0){p*=i;x/=i;y/=i;}i++;}while(x>
6、} 10.#includevoidmain(){inti,j;for(i=0;i<5;i++){for(j=i;j<5;j++)cout<<’*’;cout<voidmain(){for(inti=1,s=0;i<20;i++){if(i%2==0
7、
8、i%3==0)continue;cout<constintT=6;
9、voidmain(){inti,j;for(i=1;i<=T;i+=2)for(j=2;j<=T;j+=2){if(i+jvoidmain(){inta,b,c=0;for(a=1;a<4;a++)for(b=6;b>1;b-=2){if((a+b)%2==0)c+=a+b;elsec+=a*b;if(b==2)cout<10、stream.h>constintB=2;voidmain(){intp=1,s=1;while(s<50){p*=B;s+=p;}cout<<"s="<voidmain(){intx=24,y=88;inti=2,p=1;do{while(x%i==0&&y%i==0){p*=i;x/=i;y/=i;}i++;}while(x>
10、stream.h>constintB=2;voidmain(){intp=1,s=1;while(s<50){p*=B;s+=p;}cout<<"s="<voidmain(){intx=24,y=88;inti=2,p=1;do{while(x%i==0&&y%i==0){p*=i;x/=i;y/=i;}i++;}while(x>
此文档下载收益归作者所有