资源描述:
《实验五C程序指针运用》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、实验五C程序指针运用实验时间实验编号(填实验计算机编号)同组同学无一、实验背景1.实验题目:课本例8.1~例8.24,例8.302.稳定复杂的运算二、实验原理VisualC++6.0三、预习思考题的实验验证与题目一致四、实验过程与结果8.1#includeintmain(){inta=100,b=10;int*pointer」,*pointe「_2;pointer_1二&a;pointer_2二&b;printf("a=%d,b=%dH,a,b);printf("*pointer_l=%d,*pointer_2=%d',,*pointer_
2、l,:3:pointer_2);return0;8.2#includeintmain(){int*p],*p2,*p,a,b;printf("pleaseentertwointegernumbers:");scanf("%d,%d",&a,&b);pl二&a;p2=&b;if(aintmain(){voidswap(int*plJnt*
3、p2);inta.b;int*pointer」,*pointe「_2;printf(Hpleaseenteraandb:n);scanf(”%d,%d”,&a,&b);pointer_1二&a;pointer_2二&b;if(aintmain(){voidswap(int*pl
4、,int*p2);inta.b;int*pointer1;*pointer2;printf(Mpleaseentertwointegernumbers:H);scanf(”%d,%cT,&a,&b);pointer1=&a;pointer2二&b;if(aintmain()
5、{inta[10];inti;printf("pleaseenter10integernumbers:");for(i=0;i<10;i++)scanf("%dH,&a[i]);fdr(i=0;i<10;i++)printf(”%d”,*(a+i));printf(HH);return0;}&6.2#includeintmain(){inta[10];int*p,i;printf("pleaseenter10integernumbers:");for(i=0;i<10;i++)scanf("%dH,&a[i]);fdr(p=a;p<(a+10)
6、;p++)printf(%d",*p);printf(Hn);return0;}&7#includeintmain(){int*p,i,a[10];P=a;printf("pleaseenter10integernumbers:H);fbr(i=0;i<10;i++)scanf(“%d”,p++);for(i=0;i<10;i++,p++)printf(”%d”,*p);printf(,,M);return0;}8.8.1#includeintmain(){voidinv(intx[],intn);inti,a[10]二{
7、3,7,9,11,0,6,7,5,4,2};printf("Theoriginalarray:);fdr(i=0;i<10;i++){printf("%dH,a[i]);}printf(HH);inv(a,10);printf(HThearrayhasbeeninverted:");printf(Hn);return0;}voidinv(intx[],intn){inttemp,i,j,m=(n-l)/2;for(i=0;iv=m;i++){j=n-l-i;temp=x[i];x[i]=x[j];x[j]=temp;}return;}8.8.2#