您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 高等教育出版社出版社c语言程序设计实践教程习题参考答案(1)
高等教育出版社出版社C语言实践教程习题参考答案4.2练习题p58-59一、选择题1~5.DBADC6~7.AB二、填空题1./**/或//2.主函数或mian()3.函数的首部和函数体4.编译和连接5.;6.传统流程图和N-S图5.2练习题p64-70一、选择题1~5.ADBBC6~10.CDABB11~15.DBBCB16~20.BDDCD21~25.BADCC26~30BCDAB二、填空题1.102,102.#define符号常量常量3.x20&&x30||x-1004.15.n=16.-47.a=1,b=,c=28.c=A9.n1=%d\nn2=%d\n10.(1)a+bc&&a+cb&&b+ca(2)ch='a'&&ch='z'||ch='A'&&ch='Z'11.712.013.1111000014.8,4附录习题参考答案26.2练习题p76-84一、选择题1~5.ACDCA6~10.BADBC11~15.AACBC二、填空题1.102.y=1x%i==03.*************************4.15.136..(cx=getchar())!=-1front=cx;7.m%n8.49.(1)*p(2)px=&x(3)py=&y三、读程序,写结果1.-12.3,1,-13.a=16,y=604.x=12,y=45.59四、程序设计题1.#includestdio.hvoidmain(){floata,b,c,min;scanf(%f,%f,%f,&a,&b,&c);min=a;if(minb)min=b;if(minc)min=c;printf(%f,min);}2.方法1:#includestdio.hvoidmain()附录习题参考答案3{inta,b,c;for(a=1;a=9;a++)for(b=0;b=9;b++)for(c=0;c=9;c++)if((a*a*a+b*b*b+c*c*c)==1099)printf(%d%d%d\n,a,b,c);}方法2:#includestdio.hvoidmain(){inta,b,c,sum;for(a=100;a=999;a++){sum=0;b=a;while(b!=0){c=b%10;sum+=c*c*c;b=b/10;}if(sum==1099)printf(%5d,a);}}3.#includestdio.hvoidmain(){inti,j,k;for(i=1;i=6;i++){for(j=1;j=20-3*i;j++)printf();for(k=1;k=i;k++)printf(%3d,k);for(k=i-1;k0;k--)printf(%3d,k);printf(\n);}}4.#includestdio.hvoidmain(){floatx,fmax,fmin;scanf(%f,&x);fmax=fmin=x;while(x=0){if(xfmax)附录习题参考答案4fmax=x;elseif(xfmin)fmin=x;scanf(%f,&x);}printf(\nmax=%f,min=%f,fmax,fmin);}7.2练习题p89-96一、选择题1~5.BCCAD6~10.CDDCD11~15.DDABC16~17.BBAAD21~26.BDCDDC二、填空题1.(1)’a’(2)’\o’2.(1)a[k](2)a[k](3)a[k]3.64.ABCDEA5.1,66.k=p;7.ij8.189.4,somestring*test10.you&me三、读程序,写结果1.548202.10241563.lovechina!Hwl4.6666555v.Front四、程序设计题1.#includestdio.hvoidmain(){inti,j,a[10],k;for(i=0;i=9;i++)scanf(%d,&a[i]);for(i=0,j=9;i=j;i++,j--)附录习题参考答案5{k=a[i];a[i]=a[j];a[j]=k;}for(i=0;i=9;i++)printf(%d,a[i]);}2.#includestdio.h#includectype.hvoidmain(){chari,a[80];scanf(%s,a);for(i=0;istrlen(a);i++)if(islower(a[i]))a[i]=a[i]-32;elseif(isupper(a[i]))a[i]=a[i]+32;printf(%s,a);}3.#includestdio.hvoidmain(){chara[80],i;gets(a);for(i=strlen(p)-1;i=0;i--)putchar(a[i]);}4.#includestdio.hvoidmain(){inta[3][6],i,j;intd,d1=0,d2=0,x,x1=0,x2=0;for(i=0;i3;i++)for(j=0;j6;j++){scanf(%d,&a[i][j]);if(i==0&&j==0)x=d=a[i][j];if(da[i][j){d=a[i][j];d1=i;d2=j;}elseif(xa[i][j]){x=a[i][j];x1=i;x2=j;}p++;}printf(d=%d,d1=%d,d2=%d\n,d,d1,d2);printf(x=5d,x1=%d,x2=%d\n,x,x1,x2);附录习题参考答案6}5.#includestdio.hvoidmain(){inta[10],i,d,d1=0,x,x1=0;for(i=0;i10;i++,p++){scanf(%d,&a[i]);if(i==0){d=a[i];x=a[i];}if(da[i]){d=a[i];d1=i;}elseif(xa[i]){x=a[i];x1=i;}}a[d1]=a[0];a[0]=d;a[x1]=a[9];a[9]=x;for(i=9;i=0;i--,p--)printf(%d,,*p);}8.2练习题p106-114一、选择题1~5.AABBB6~10.ADCAA11~15.ABBAB16~17.BC二、填空题1.122.(1)Itis3.(1)n*fun(n-1)(2)fun(k)4.s[i]-t[i]5.(1)n%m(2)i-1(3)x[d];6.(1)x=n;(2)n%10(3)x7.m=f(a,4)+f(b,4)-f(a+b,3)8.a=1,b=1;三、读程序,写结果1.s=72.s=373.bij12四、程序设计题1.intnian(inty){if((y%4==0)&&(y%100!=0)||(y%400==0))return1;elsereturn0;}2.voidfun(floata[],floatb[]){inti;附录习题参考答案7floats=0;b[0]=b[1]=a[0];for(i=0;in;i++){s=s+a[i];if(b[0]a[i])b[0=a[i];elseif(b[1]a[i])b[1]=a[i];}b[2]=s/n;}3.intcout(charstr[],charsub[]){inti,j,k;intcount=0;for(i=0;str[i];i++)for(j=i,k=0;sub[k]==str[j];k++,j++)if(sub[k+1]=='\0'){count++;break;}returncount;}4.#includestdio.hvoidpp(intm){intj;if(j=m/10)pp(j);putchar(n%10+'0');}voidmain(){intn;scanf(%d,&n);if(n0){putchar('-');n=-n;}pp(n);}5.#includestdio.hintadd(intn){intr,s=0;do{r=n%10;附录习题参考答案8s+=r;n=n/10;}while(n0);returns;}voidmain(){inta;scanf(%d,&a);printf(%d,add(a));}6.#includemath.h#includestdio.hvoidprime(intn){inti,f=1;for(i=2;i=sqrt(n);i++)if(n%i==0){f=0;break;}}voidmain(){intm;scanf(%d,&m);if(prime(m))printf(%d,m);elseprintf(不是素数);}7.参考程序inttotal(chars[],charch){inti=0,n=0;while(s[i])if(s[i++]==ch)n++;return(n);}#includestdio.hvoidmain(){chars[20],ch;gets(s);ch=getchar();printf(%d,total(s,ch));}8.voidmove(char*x,intn,intm)附录习题参考答案9{inti,j;for(j=0;jm;j++){charw=*(x+n-1);for(i=0;in-1;i++)*(x+n-1-i)=*(x+n-2-i);*x=w;}}9.voidprint(char*string){char*str=string;if(*str=='\0')return;while(*str)str++;putchar(*--str);*str='\0';print(string);}
本文标题:高等教育出版社出版社c语言程序设计实践教程习题参考答案(1)
链接地址:https://www.777doc.com/doc-1936685 .html