1、高等教育出版社出版社C 语言实践教程习题参考答案4.2 练习题 p58-59一、选择题15DBADC 67AB 二、填空题1/* */ 或/ 2主函数或 mian() 3函数的首部和函数体 4 编译和连接5; 6传统流程图和 N-S 图5.2 练习题 p64-70一、选择题15ADBBC 610CDABB 1115DBBCB 1620BDDCD 2125BADCC 2630 BCDAB 二、填空题1102,10 2#define 符号常量 常量3x20scanf(“%f,%f,%f“,min=a;if (minb) min=b;if (minc) min=c;printf(“%f“,min);
2、2方法 1:#include void main()附录 习题参考答案 3int a,b,c;for (a=1;avoid main()int a,b,c,sum;for (a=100;avoid main()int i,j,k;for (i=1;i0;k-) printf(“%3d“,k);printf(“n“);4#include void main()float x,fmax,fmin;scanf(“%f“,fmax=fmin=x;while (x=0)if (xfmax)附录 习题参考答案 4fmax=x;elseif (xvoid main()int i,j,a10,k;for(i=
3、0;i#include void main()char i,a80;scanf(“%s“,a);for(i=0;ivoid main()char a80,i;gets(a);for(i=strlen(p)-1;i=0;i-)putchar(ai);4#include void main()int a36,i,j;int d,d1=0,d2=0,x,x1=0,x2=0;for(i=0;iaij) x=aij;x1=i;x2=j;p+;printf(“d=%d,d1=%d,d2=%dn“,d,d1,d2);printf(“x=5d,x1=%d,x2=%dn“,x,x1,x2);附录 习题参考答案
4、65#include void main()int a10,i,d,d1=0,x,x1=0;for(i=0;iai) x=ai;x1=i;ad1=a0;a0=d;ax1=a9;a9=x;for(i=9;i=0;i-,p-)printf(“%d,“,*p);8.2 练习题 p106-114一、选择题15AABBB 610ADCAA 1115ABBAB 1617BC二、填空题112 2 (1)Itis 3(1)n*fun(n-1) (2)fun(k) 4si-ti 5(1)n%m (2)i-1 (3)xd; 6 (1)x=n; (2)n%10 (3) x 7m= f(a,4)+f(b,4)-f(a
5、+b,3) 8a=1,b=1; 三、读程序,写结果1s=7 2s=373.bij12四、程序设计题1int nian(int y)if(y%4=0)else return 0;2void fun(float a,float b)int i;float s=0;b0=b1=a0;附录 习题参考答案 7for(i=0;iai) b1=ai;b2=s/n;3int cout(char str,char sub)int i,j,k;int count=0;for(i=0;stri;i+)for(j=i,k=0;subk= =strj;k+,j+)if(subk+1=0)count+;break;ret
6、urn count;4#include “stdio.h“void pp(int m)int j;if(j=m/10) pp(j);putchar(n%10+0);void main()int n;scanf(“%d“,if(n0);return s;void main()int a;scanf(“%d“,printf(“%d“, add(a);6#include #include “stdio.h“ void prime(int n)int i,f=1;for(i=2;i=sqrt(n);i+)if(n%i= =0)f=0;break;void main()int m;scanf(“%d“,
7、if(prime(m) printf(“%d“, m);else printf(“不是素数“) ;7参考程序int total(char s ,char ch)int i=0,n=0;while(si)if(si+=ch) n+;return(n);#include “stdio.h“ void main()char s20,ch;gets(s);ch=getchar();printf(“%d“, total(s,ch);8void move(char *x,int n,int m)int i,j;for(j=0;jm;j+)附录 习题参考答案 9char w=*(x+n-1);for(i=0;in-1;i+)*(x+n-1-i)=*(x+n-2-i);*x=w;9void print(char *string)char *str=string;if(*str=0)return;while(*str)str+;putchar(*-str);*str=0;print(string);