1、P115 第 7 章 数组参考答案四、编程题1. 参考程序:#includemain()float a30,sum=0,ave;int n=0,i,k=0;printf(“please input score:“);for(i=0;iave)k+;printf(“renshuwei:%dn“,k);2.数组逆序排列参考程序:#include #define N 10main( ) int aN, temp, i;for (i = 0 ; i #define N 10main( )int aNN;int i, j;for (i = 0 ; i int prime(int x)int i;int
2、flag=1;for(i=2;ilong fun(char str);main()char datastring10;long data;printf(“Please input data string:“);scanf(“%s“, datastring);data=fun(datastring);printf(“output number:“);printf(“%ldn“, data); long fun(char str)int i;long data;data=0;for(i=0;stri!=0;i+)data=data*10+(stri-0);return data;P140 第九章
3、编译预处理参考答案P142 第十章 指针参考答案四、编程题1. void swap(int *p1,int *p2)int temp;temp=*p1;*p1=*p2;*p2=temp;main()int a,b,*p1=sacnf(“%d%d”,p1,p2);swap(p1,p2)printf(“%d,%d”,a,b);2.main()float he(float ,float);float cha(float ,float);float ji(float ,float);float shang(float ,float);void process(float ,float ,float (
4、 *fun)(float ,float);float a,b;scanf(“%f,%f”,printf(“he=”);process(a,b,he);printf(“cha=”);process(a,b,cha);printf(“ji=”);process(a,b,ji);printf(“shang=”);process(a,b,shang); float he(float x,float y)return (x+y);float cha(float x,float y)return (x-y);float ji(float x,float y)return (x*y);float shang
5、(float x,float y)return (x/y);void process(float x,float y,float (*fun)(float ,float)float result;result=(*fun)(x,y);printf(“%fn”,result);3. int fun(char *p)char *f;f=p;while(*p!=0)p+;return p-f;main()char s100,*p;scanf(“%s“,s);p=s;printf(“%dn“,fun(p);P153 第 11 章 结构体与共用体参考答案四、编程题1. 参考程序:#include #de
6、fine N 5struct studentlong num;char name20;float score3;void input(struct student w, int n);void output(struct student w, int n);main()struct student stN;int n;printf(“Please input the number of worker(10):“);scanf(“%d“, input(st, n);output(st, n);void input(struct student w, int n)int i, j;float temp;for(i=0;in;i+)printf(“Please input NO %dn“, i+1);printf(“Num:“); scanf(“%ld“,getchar();printf(“name:“); gets(wi.name);for (j=0; j 3; j+) printf(“Score%d=”, j);scanf(“%f“,wi.scorej = temp;void output(struct student w, int n)int i, j;for(i=0;in;i+)