欢迎来到天天文库
浏览记录
ID:55951010
大小:50.50 KB
页数:13页
时间:2020-06-18
《c++指针类练习题及答案.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、1、利用指针,编写用于交换两个整型变量值的函数。程序运行结果如下:输入:56输出:65#includeusingnamespacestd;voidswap(int*xp,int*yp){ inttmp; tmp=*xp; *xp=*yp; *yp=tmp;}intmain(){ inta,b; cin>>a>>b; swap(&a,&b); cout<2、GHIJK输出:KJIHGFEDCBA#include#includeusingnamespacestd;intmain(){ charstr[100]; cin>>str; intlen; len=strlen(str); char*p=&str[len-1]; while(p>=str) { cout<<*p; p--; } cout<3、,排序方法使用简单选择排序法。程序的运行结果如下所示:输入(第一个数是序列的长度):6272231输出:122237#includeusingnamespacestd;voidselectsort(int*list,intcount){ for(inti=0;i4、 { inttmp=*(list+i); *(list+i)=*(list+k); *(list+k)=tmp; } }}intmain(){ intn; cin>>n; intarray[20]; for(intj=0;j>array[j]; selectsort(array,n); for(inti=0;i5、out<usingnamespacestd;voidbubble_up(int*ptr,intcount){ for(inti=0;i6、1) for(intj=count-1;j>i;j=j-1) if(*(ptr+j-1)>*(ptr+j)) { inttmp=*(ptr+j-1); *(ptr+j-1)=*(ptr+j); *(ptr+j)=tmp; }}intmain(){ intn; cin>>n; intlist[100]; for(intx=0;x7、 cin>>list[x]; bubble_up(list,n); for(inti=0;iusingnamespacestd;intmain(){ intn8、,i=1;chara[20],*ptr;ptr=a;cin>>n;do{ if(i%4) { *ptr=n%10+'0';
2、GHIJK输出:KJIHGFEDCBA#include#includeusingnamespacestd;intmain(){ charstr[100]; cin>>str; intlen; len=strlen(str); char*p=&str[len-1]; while(p>=str) { cout<<*p; p--; } cout<3、,排序方法使用简单选择排序法。程序的运行结果如下所示:输入(第一个数是序列的长度):6272231输出:122237#includeusingnamespacestd;voidselectsort(int*list,intcount){ for(inti=0;i4、 { inttmp=*(list+i); *(list+i)=*(list+k); *(list+k)=tmp; } }}intmain(){ intn; cin>>n; intarray[20]; for(intj=0;j>array[j]; selectsort(array,n); for(inti=0;i5、out<usingnamespacestd;voidbubble_up(int*ptr,intcount){ for(inti=0;i6、1) for(intj=count-1;j>i;j=j-1) if(*(ptr+j-1)>*(ptr+j)) { inttmp=*(ptr+j-1); *(ptr+j-1)=*(ptr+j); *(ptr+j)=tmp; }}intmain(){ intn; cin>>n; intlist[100]; for(intx=0;x7、 cin>>list[x]; bubble_up(list,n); for(inti=0;iusingnamespacestd;intmain(){ intn8、,i=1;chara[20],*ptr;ptr=a;cin>>n;do{ if(i%4) { *ptr=n%10+'0';
3、,排序方法使用简单选择排序法。程序的运行结果如下所示:输入(第一个数是序列的长度):6272231输出:122237#includeusingnamespacestd;voidselectsort(int*list,intcount){ for(inti=0;i4、 { inttmp=*(list+i); *(list+i)=*(list+k); *(list+k)=tmp; } }}intmain(){ intn; cin>>n; intarray[20]; for(intj=0;j>array[j]; selectsort(array,n); for(inti=0;i5、out<usingnamespacestd;voidbubble_up(int*ptr,intcount){ for(inti=0;i6、1) for(intj=count-1;j>i;j=j-1) if(*(ptr+j-1)>*(ptr+j)) { inttmp=*(ptr+j-1); *(ptr+j-1)=*(ptr+j); *(ptr+j)=tmp; }}intmain(){ intn; cin>>n; intlist[100]; for(intx=0;x7、 cin>>list[x]; bubble_up(list,n); for(inti=0;iusingnamespacestd;intmain(){ intn8、,i=1;chara[20],*ptr;ptr=a;cin>>n;do{ if(i%4) { *ptr=n%10+'0';
4、 { inttmp=*(list+i); *(list+i)=*(list+k); *(list+k)=tmp; } }}intmain(){ intn; cin>>n; intarray[20]; for(intj=0;j>array[j]; selectsort(array,n); for(inti=0;i5、out<usingnamespacestd;voidbubble_up(int*ptr,intcount){ for(inti=0;i6、1) for(intj=count-1;j>i;j=j-1) if(*(ptr+j-1)>*(ptr+j)) { inttmp=*(ptr+j-1); *(ptr+j-1)=*(ptr+j); *(ptr+j)=tmp; }}intmain(){ intn; cin>>n; intlist[100]; for(intx=0;x7、 cin>>list[x]; bubble_up(list,n); for(inti=0;iusingnamespacestd;intmain(){ intn8、,i=1;chara[20],*ptr;ptr=a;cin>>n;do{ if(i%4) { *ptr=n%10+'0';
5、out<usingnamespacestd;voidbubble_up(int*ptr,intcount){ for(inti=0;i6、1) for(intj=count-1;j>i;j=j-1) if(*(ptr+j-1)>*(ptr+j)) { inttmp=*(ptr+j-1); *(ptr+j-1)=*(ptr+j); *(ptr+j)=tmp; }}intmain(){ intn; cin>>n; intlist[100]; for(intx=0;x7、 cin>>list[x]; bubble_up(list,n); for(inti=0;iusingnamespacestd;intmain(){ intn8、,i=1;chara[20],*ptr;ptr=a;cin>>n;do{ if(i%4) { *ptr=n%10+'0';
6、1) for(intj=count-1;j>i;j=j-1) if(*(ptr+j-1)>*(ptr+j)) { inttmp=*(ptr+j-1); *(ptr+j-1)=*(ptr+j); *(ptr+j)=tmp; }}intmain(){ intn; cin>>n; intlist[100]; for(intx=0;x7、 cin>>list[x]; bubble_up(list,n); for(inti=0;iusingnamespacestd;intmain(){ intn8、,i=1;chara[20],*ptr;ptr=a;cin>>n;do{ if(i%4) { *ptr=n%10+'0';
7、 cin>>list[x]; bubble_up(list,n); for(inti=0;iusingnamespacestd;intmain(){ intn
8、,i=1;chara[20],*ptr;ptr=a;cin>>n;do{ if(i%4) { *ptr=n%10+'0';
此文档下载收益归作者所有