资源描述:
《C语言程序设计第5篇习题答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1.选择题(1)C(2)D(3)C(4)B(5)A(6)A(7)A(8)B(9)A(10)B(11)A(12)A2.填空题(1)整型(2)值传递地址传递(3)全局变量局部变量(4)自动变量静态变量寄存器变量外部变量(5)自动变量(6)15300(7)8121(8)x=3,y=4,n=7(9)563.程序设计题(1)#includeintgcd_recursion(inta,intb);voidmain(){inti,j;puts("Pleaseenter2integer");scanf("%d,%d",&i,&j);if(i<0
2、
3、j
4、<0){puts("DataError!Pleaseenter2integer");scanf("%d,%d",&i,&j);}elseprintf("gcd(%d,%d)=%d",i,j,gcd_recursion(i,j));}intgcd_recursion(inta,intb){intc,d;if(a
5、includeintdelete_char(charc,charstr[]);voidmain(){charstr[10],c,i;puts("Pleaseenterastring:");gets(str);puts("Pleaseenteracharyouwanttodelete:");c=getchar();puts("Beforedeleted:");puts(str);puts("Afterdeleted:");i=delete_char(c,str);puts(str);printf("Thereare%dcharacter
6、sdeleted.",i);}intdelete_char(charc,charstr[]){inti,j,total,k,sum;i=0;total=0;while(str[i]!=' '){k=i;sum=0;while(str[k]==c){k++;sum++;}total=total+sum;if(str[i]==c){for(j=i;str[j+sum]!=' ';j++)str[j]=str[j+sum];str[j]=' ';}i++;}returntotal;}(3)#includeintmax(inta,intb)
7、;voidmain(){inti,j,k;puts("Pleaseenter3integer:");scanf("%d,%d,%d",&i,&j,&k);printf("maxis%d.",max(max(i,j),k));}intmax(inta,intb){if(a>b)returna;elsereturnb;}(4)#includevoidint_string(longa,charstr[]);voidreverse(charc[],intsize);voidinsert_space(charc[],intsize);voidm
8、ain(){longi;charstr1[10];puts("Pleaseenter1longinterger:");scanf("%d",&i);int_string(i,str1);printf("digitalstringis%s",str1);}voidint_string(longa,charstr[]){inti=0;while(a!=0){str[i]=a%10+'0';a=a/10;i++;}str[i]=' ';insert_space(str,i);}voidinsert_space(charc[],intsize){inti;c
9、[2*size-1]=' ';for(i=2*(size-1);i>=2;i-=2){c[i]=c[i/2];c[i-1]='';}}(5)#includelongfacto(longx);main(){inta;longfactorial;printf("Pleaseenterainteger:");scanf("%d",&a);factorial=facto(a);printf("The%d'sjiecengis:%ld",a,factorial);}longfacto(longx){if(x==1)return1;el
10、sereturn(x*facto(x-1));}(6)#inclu