欢迎来到天天文库
浏览记录
ID:15658133
大小:136.00 KB
页数:6页
时间:2018-08-04
《高级语言程序设计(c++)数组习题及答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、数组习题参考答案一、找出下面程序或程序段中的错误,并改正。1.#includeusingnamespacestd;intmain(){intm,a[m];a[0]=1;cout<usingnamespacestd;intmain(){constintm=10;inta[m];a[0]=1;cout<usingnamespacestd;intmain(){inta[5];cin>>a;cout<2、return0;}正确程序:#includeusingnamespacestd;intmain(){inta[5];cin>>a[4];cout<usingnamespacestd;intmain(){charc[10]="Iamastudent";cout<usingnamespacestd;intmain(){charc[]="Iamastudent";cout<3、China¿,要求输出China#includeusingnamespacestd;intmain(){chara[5],*p;inti;*p=a;for(i=0;i<5;i++)cin>>*(p+i);cout<usingnamespacestd;intmain(){chara[6],*p;inti;p=a;for(i=0;i<5;i++)cin>>*(p+i);a[5]=' ';cout<4、>usingnamespacestd;intmain(){inti,k,a[10],p[3];k=5;for(i=0;i<10;i++)a[i]=i;for(i=0;i<3;i++)p[i]=a[i*(i+1)];for(i=0;i<3;i++)k+=p[i]*2;cout<usingnamespacestd;intmain(){inty=25,i=0,j,a[8];do{a[i]=y%2;i++;y=y/2;}while(y>=1);for(j=i-5、1;j>=0;j--)cout<#includeusingnamespacestd;intmain(){intt[3][4]={{1,2,3,4},{5,6,7,8},{9}},i,j;for(i=0;i<3;i++)for(j=0;j<4;j++)cout<6、++)cout<usingnamespacestd;intmain(){chart[3][20]={"Watermelon","Strawberry","grape"};inti;for(i=0;i<3;i++)cout<7、;}运行结果:WatermelonStrawberrygrape4.#includeusingnamespacestd;#includevoidsort(inta[],intn){inti,j,t;for(i=0;i
2、return0;}正确程序:#includeusingnamespacestd;intmain(){inta[5];cin>>a[4];cout<usingnamespacestd;intmain(){charc[10]="Iamastudent";cout<usingnamespacestd;intmain(){charc[]="Iamastudent";cout<3、China¿,要求输出China#includeusingnamespacestd;intmain(){chara[5],*p;inti;*p=a;for(i=0;i<5;i++)cin>>*(p+i);cout<usingnamespacestd;intmain(){chara[6],*p;inti;p=a;for(i=0;i<5;i++)cin>>*(p+i);a[5]=' ';cout<4、>usingnamespacestd;intmain(){inti,k,a[10],p[3];k=5;for(i=0;i<10;i++)a[i]=i;for(i=0;i<3;i++)p[i]=a[i*(i+1)];for(i=0;i<3;i++)k+=p[i]*2;cout<usingnamespacestd;intmain(){inty=25,i=0,j,a[8];do{a[i]=y%2;i++;y=y/2;}while(y>=1);for(j=i-5、1;j>=0;j--)cout<#includeusingnamespacestd;intmain(){intt[3][4]={{1,2,3,4},{5,6,7,8},{9}},i,j;for(i=0;i<3;i++)for(j=0;j<4;j++)cout<6、++)cout<usingnamespacestd;intmain(){chart[3][20]={"Watermelon","Strawberry","grape"};inti;for(i=0;i<3;i++)cout<7、;}运行结果:WatermelonStrawberrygrape4.#includeusingnamespacestd;#includevoidsort(inta[],intn){inti,j,t;for(i=0;i
3、China¿,要求输出China#includeusingnamespacestd;intmain(){chara[5],*p;inti;*p=a;for(i=0;i<5;i++)cin>>*(p+i);cout<usingnamespacestd;intmain(){chara[6],*p;inti;p=a;for(i=0;i<5;i++)cin>>*(p+i);a[5]=' ';cout<4、>usingnamespacestd;intmain(){inti,k,a[10],p[3];k=5;for(i=0;i<10;i++)a[i]=i;for(i=0;i<3;i++)p[i]=a[i*(i+1)];for(i=0;i<3;i++)k+=p[i]*2;cout<usingnamespacestd;intmain(){inty=25,i=0,j,a[8];do{a[i]=y%2;i++;y=y/2;}while(y>=1);for(j=i-5、1;j>=0;j--)cout<#includeusingnamespacestd;intmain(){intt[3][4]={{1,2,3,4},{5,6,7,8},{9}},i,j;for(i=0;i<3;i++)for(j=0;j<4;j++)cout<6、++)cout<usingnamespacestd;intmain(){chart[3][20]={"Watermelon","Strawberry","grape"};inti;for(i=0;i<3;i++)cout<7、;}运行结果:WatermelonStrawberrygrape4.#includeusingnamespacestd;#includevoidsort(inta[],intn){inti,j,t;for(i=0;i
usingnamespacestd;intmain(){chara[6],*p;inti;p=a;for(i=0;i<5;i++)cin>>*(p+i);a[5]=' ';cout<
4、>usingnamespacestd;intmain(){inti,k,a[10],p[3];k=5;for(i=0;i<10;i++)a[i]=i;for(i=0;i<3;i++)p[i]=a[i*(i+1)];for(i=0;i<3;i++)k+=p[i]*2;cout<usingnamespacestd;intmain(){inty=25,i=0,j,a[8];do{a[i]=y%2;i++;y=y/2;}while(y>=1);for(j=i-
5、1;j>=0;j--)cout<#includeusingnamespacestd;intmain(){intt[3][4]={{1,2,3,4},{5,6,7,8},{9}},i,j;for(i=0;i<3;i++)for(j=0;j<4;j++)cout<6、++)cout<usingnamespacestd;intmain(){chart[3][20]={"Watermelon","Strawberry","grape"};inti;for(i=0;i<3;i++)cout<7、;}运行结果:WatermelonStrawberrygrape4.#includeusingnamespacestd;#includevoidsort(inta[],intn){inti,j,t;for(i=0;i
6、++)cout<usingnamespacestd;intmain(){chart[3][20]={"Watermelon","Strawberry","grape"};inti;for(i=0;i<3;i++)cout<7、;}运行结果:WatermelonStrawberrygrape4.#includeusingnamespacestd;#includevoidsort(inta[],intn){inti,j,t;for(i=0;i
7、;}运行结果:WatermelonStrawberrygrape4.#includeusingnamespacestd;#includevoidsort(inta[],intn){inti,j,t;for(i=0;i
此文档下载收益归作者所有