资源描述:
《C语言阅读程序模拟题》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、阅读程序模拟题1.下面程序执行结果是#includevoidswap(int*,int*);voidmain(){inta=5,b=7,*ptr1,*ptr2;ptr1=&a,ptr2=&b;swap(ptr1,ptr2);printf(“*ptr1=%d,*ptr2=%d”,*ptr1,*ptr2);printf(“a=%d,b=%d”,a,b);}voidswap(int*p1,*p2){intp;p=*p1;*p1=*p2;*p2=p;}2.输入wearestudents,下面程序运行结果#includevoidmain
2、(){charstring[81];inti,num=0,word=0;charc;gets(string);for(i=0;(c=string[i])!=' ';i++)if(c=='')word=0;elseif(word==0){word=1;num++;}printf("%d",num);}3.下面程序的运行结果是Thearrayhasbeenreverted:2,4,5,7,6,0,11,9,7,3#includevoidinv(intx[],intn);voidmain(){inti,a[10]={3,7,9,11,0,6,7,5,4
3、,2};inv(a,10);printf("Thearrayhasbeenreverted:");for(i=0;i<10;i++)printf("%d,",a[i]);printf("");}voidinv(intx[],intn){intt,i,j,m=(n-1)/2;for(i=0;i<=m;i++){j=n-1-i;t=x[i];x[i]=x[j];x[j]=t;}}4.下面程序的运行结果是#includevoidcopy_string(char*,char*);voidmain(){char*a="Iamateacher.";char
4、*b="Youareastudent.";copy_string(a,b);printf("string_a=%sstring_b=%s",a,b);}voidcopy_string(char*from,char*to){for(;*from!=' ';from++,to++)*to=*from;*to=' ';}5.下面程序的运行的功能是BASIC#include#includevoidsort(char*name[],int);voidprint(char*name[],int);voidmain(){char*
5、name[]={"Followme","BASIC","GreatWall","FORTRAN","Computer"};intn=5;sort(name,n);print(name,n);}voidsort(char*name[],intn){char*temp;inti,j,k;for(i=0;i0)k=j;if(k!=i){temp=name[i];name[i]=name[k];name[k]=temp;}}}voidprint(char*nam
6、e[],intn){inti;for(i=0;ilongintfac(int);voidmain(){intn;scanf("%d",&n);printf("%d",fac(n));}longintfac(intm){longintf;if(m<0)printf("dataerror!");elseif(m==0
7、
8、m==1)f=1;elsef=fac(m-1)*m;returnf;}7.下面程序执行的结果是:输入如下数据:LiZhangLiLiW
9、angZhangWangZhang#includestructperson{charname[20];intcount;}leader[3]={"Li",0,"Zhang",0,"Wang",0};voidmain(){inti,j;charleader_name[20];for(i=1;i<=8;i++){scanf("%s",leader_name);for(j=0;j<3;j++)if(strcmp(leader_name,leader[j].name)==0)leader[j].count++;}for(i=0;