C语言程序设计张淑华、朱丽莉版课后习的题目参考详解_第1页
C语言程序设计张淑华、朱丽莉版课后习的题目参考详解_第2页
C语言程序设计张淑华、朱丽莉版课后习的题目参考详解_第3页
C语言程序设计张淑华、朱丽莉版课后习的题目参考详解_第4页
C语言程序设计张淑华、朱丽莉版课后习的题目参考详解_第5页
免费预览已结束,剩余16页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、实用标准文案C语言程序设计张淑华、朱丽莉主编课后习题解答仅供参考、选择题1 . B6. C二、填空题1 . .obj 2函数./* */.#include<stdio.h> inta,b; a,b三、简做题略、选择题1 .B2.B3.A4.D5.A6.C7.C8.A9.C10.B11.,A12.A13.C14.A15.C二、填空题1.变量5. 16.存储数据的单元.非0、.38(1)a>=0 (2)0. 4 , 710. -6 17777211.9.912三、写出以下程序的运行结果1. 0, 0, 52. 185. d4,c512四、编程题1 . #include <s

2、tdio.h>#define PI 3.1415926void main()float r,s; printf( scanf( s=PI*r*r; printf(“Please input circinal radiin "f,&r);“r=%.2f,s=%.2fn ,r,s););2.#include <stdio.h>void main()精彩文档实用标准文案 char c1,c2;printf( " Please input a majusculen ");scanf("%C ,&c1);c2=c1>'

3、; A &&c1<' Z' ?c1+32:c1;printf(" cn,c2);3. #include <stdio.h>void main() int a=0,b;scanf("%C ,&b);b=b&a;printf(" b=%dn ,b);习题三一、选择题1. C 2, C 3.A 4. C 5. D6 .原题第2行应为c=(c-=a-5),(a=b,b+3); 答案为B否那么输出结果为5,0,57 . D 8. C 9. A 10. B二、填空题1 . -50 300、a=-50,b=300

4、a=-50b=3002. 10 20 30、10,20,30、a=10,b=20,c=303. 15、 0、 0三、写出以下程序的运行结果1 . a=789.654321,a= 789.65,a= 789.65432100,a=789.6543212. b=15,b=17,b=f35.在TC环境下为216,125.c=1,x=0,y=0,z=1420,20在VC环境下为216,1809,4,12,126 . a=A,b=d,c=F 8. x=4.500000,y=4,x+y=8.500000四、编程题1 . #include <stdio.h>void main()printf(*

5、n");printf(" HAPPY NEW YEAR! n");2.printf("*n");精彩文档实用标准文案(1) #include <stdio.h> void main() int a=5,b=8,c=10,m,max;m= a>b?a:b;max=c>m?c:m;printf("max=%dn' ,max);(2)#include <stdio.h>void main() int a,b,c,m,max;scanf("%d,%d,%d",&a,&am

6、p;b,&c);max=a>b?a:(b>c?b:c);printf("max=%drT ,max);、选择题1 . D2.D3.C46. A7.C8.C9、填空题1. 6、5、52. (a%3=0|a%7=0)3 a>b (2) a=c; a,b,c三、写出以下程序的运行结果1. 42. 643. a=7,b=446四、编程题1.另见填空题3#include <stdio.h>void main() float a,b,c,t;scanf("%f,%f,%f",&a,&b,&c);if (a>b

7、) t=a;a=b;b=t;if (a>c)t=a;a=c;c=t;if (b>c)t=b;b=c;c=t;printf( ".2f,%.2f,%.2fn",a,b,c);4. 46465*#2. #include <stdio.h>void main()精彩文档实用标准文案 int a,b;scanf("%d,%d",&a,&b);if(a%b=0)printf("%d is divisible by %dn ,a,b);elseprintf("%d is not divisible by %

8、dn ,a,b);3. (1) #include <stdio.h>void main() int x,y;scanf("%d ,&x);if (x>-5&&x<0)y=x;printf("y=%dn",y);else if (x=0)y=x-1;printf("y=%dn",y);else if(x>0&&x<10)y=x+1;printf("y=%dn",y);elseprintf("Data out of rangen");

9、(2) #include <stdio.h>void main() int x,y;scanf("%d',&x);switch(x) case -1:case -2:case -3:case -4:y=x; printf("y=%dn",y);break;case 0:y=x-1; printf("y=%dn",y);break;case 1:case 2:case 3:case 4:case 5:case 6:case 7:case 8:case 9:y=x+1; printf("y=%dn",

10、y);break;default: printf("Data out of rangen");精彩文档实用标准文案4. #include <stdio.h>void main()(long num;int indiv,ten,hundred,thousand,tenthousand,place;/*分别代表个位、十位、百位、千位、万位和位数 */printf( "Please Input a integer(099999):");scanf( "%ld ,&num);if (num>9999)place=5;else

11、if (num>999)place=4;else if (num>99)place=3;else if (num>9)place=2;elseplace=1;printf("place=%dn " ,place);printf("For each digit: ");tenthousand=num/10000;thousand=(int)(num-tenthousand*10000)/1000;hundred=(int)(num-tenthousand*10000-thousand*1000)/100;ten=(int)(num-ten

12、thousand*10000-thousand*1000-hundred*100)/10;indiv=(int)(num-tenthousand*10000-thousand*1000-hundred*100-ten*10);switch(place)(case 1:printf("%d ,indiv);break;case 2:printf("%d,%d ,ten,indiv);break;case 3:printf("%d,%d,%d ,hundred,ten,indiv);break;case 4:printf("%d,%d,%d,%d ,thou

13、sand,hundred,ten,indiv);break;case5:printf( " %d,%d,%d,%d,%d ,tenthousand,thousand,hundred,ten,indiv);)习题五D4. B5. CB9. B10. B一、选择题1. D2, C36. B7, C8二、填空题1. (1) x>=0 或!(x<0)(2) x<amin精彩文档实用标准文案)j%3 或 j%3!=02. (1) i<10 或 i<=9(23. (1) pi (2) fabs(t) (3)4三、写出以下程序的运行结果1 . 16. 45.a=2,b

14、=853423四、编程题1. #include <stdio.h>void main() int i,j,k;输出上面4彳T*号*/for (i=1;i<=4;i+) /* for (j=1;j<=5-i;j+)printf(");/* 输出*号前面白空格*/for (k=1;k<=2*i-1;k+)2.printf( printf( );/* 输出*号*/“n");/*输出完一行*号后换行*/#include "stdio.h"void main() int num,n1,n2,p=1;scanf("%d&quo

15、t;,&num);while (num) n1=num/10;n2=num%10;p*=n2;num=n1;)printf("num=%d,p=%dn",num,p);3.)#include "stdio.h"void main() int i;float s1,s2,s3,s4,s5,sum,avg;for(i=1;i<=6;i+) printf("Please enter a five subjects scoren");scanf("%f,%f,%f,%f,%f",&s1,&s2

16、,&s3,&s4,&s5);sum=0;sum+=s1+s2+s3+s4+s5;avg=sum/5;精彩文档实用标准文案printf("%d individuals,the average score is %.2fn",i,avg);习题六一、选择题1. D2. C36. A7. C8二、填空题.3. (1) j=9 (2) j>=04. (1) 0 (2).(1) i<3 (2)aii1 .地址常量 2 .非036 5. (1) gets(temp); (2) strcpy(temp,str); 67. (1) &ai(2)

17、i%4=0(3)printf("n:");8. (1) si>=48 && si<=57或 si>='0' && si<='9' (2) dj=0;或 dj='0'三、写出以下程序的运行结果1. 137152. s=153. 584. 115.7 06. how7. max=9,row=1,col=0 8. 6,4,3,2,are you? I am fine四、编程题1 . #include <stdio.h>#define N 10 void main()

18、 int a32,x,k,r,i;printf( " Please input an integer:");k=-1;do r=x%2;a+k=r;x/=2;)while(x>=1);for(i=k;i>=0;i-)printf( "1d ,ai);printf( "n );)2. #include <stdio.h>#define N 10 void main() int aN+1=10,20,30,40,50,60,70,80,90,100;int t1,t2,num,i,j;精彩文档实用标准文案printf( "a

19、rray a:n ");for (i=0;i<N;i+)printf( "%d ,ai);printf("n );printf("Insert data:");scanf( "%d' ,&num);if (num>aN-1) aN=num;else for (i=0;i<N;i+) if (ai>num) t1=ai;ai=num;for (j=i+1;j<N+1;j+) t2=aj;aj=t1;t1=t2; break;printf("Current array a:n&quo

20、t;);for (i=0;i<N+1;i+)printf( "%5dn",ai);3. #include <stdio.h>#define N 6void main() int i,j,aNN;for (i=1;i<N;i+) aii=1;ai1=1;for (i=3;i<N;i+)for (j=2;j<i-1;j+)aij=ai-1j-1+ai-1j;for (i=1;i<N;i+) for (j=1;j<=i;j+)printf( "5d ,aij); printf( " n " );4. #

21、include "stdio.h" void main() char s80,t80,d;int i,j;printf("Please enter a string:n");gets(s);精彩文档实用标准文案printf("delete?n");d=getchar();for(i=j=0;si!='0'i+)if(si!=d)tj=si;j+; tj='0'printf("%sn",t);5. #include "stdio.h"#define N 8 void

22、 main() int sN3,i,j,k,m,t1;float aN,sum,t2;for(i=0;i<N;i+) printf("Please enter the %d-th three subjects scoren",i); sum=0;for(j=0;j<3;j+) scanf("%d",&sij); sum+=sij;ai=sum/3;for(i=0;i<N-1;i+) k=i;for(j=i+1;j<N;j+) if(ak<aj) k=j; if(k!=i) for(m=0;m<3;m+) t1=

23、sim;sim=skm;skm=t1; /*交换整行的值 */t2=ai;ai=ak;ak=t2;for(i=0;i<N;i+) printf("%d-th ",i);for(j=0;j<N;j+)printf("%d ",sij);printf("%.2fn",ai); 习题七一、选择题1. C 2.A 3. B 4. B 5.A精彩文档实用标准文案6. D 7, C 8. D 9. C 10. C二、填空题1 . struct STRU t20;2. x.x、x.y、x.z.y、x.z.z 3. 4,8三、写出以下程序

24、的运行结果1 . 62. 03. 4E5S 4. 215. Zhao,m,85,90四、编程题2 . #include "stdio.h"#define N 45 struct student char name20;char sex7;int age;int score;stdN;void main() int i,max=0,rowi;for(i=0;i<N;i+) printf("Please enter the data of the %d-th student:n",i);printf("name:");scanf(&

25、quot;%s",);printf("sex:");scanf("%s",stdi.sex);printf("age:");scanf("%d",&stdi.age);printf("score:");scanf("%d",&stdi.score);if(max<stdi.score) max=stdi.score; rowi=i;printf("name:%s ",);printf

26、("sex:%s ",stdrowi.sex);printf("age:%d ",stdrowi.age);printf("score:%dn",stdrowi.score);3 . #include "stdio.h"#define N 5 struct student char name20;char sex7;精彩文档实用标准文案int score;stdN;void main() int i,ml=0,fml=0;float sum=0,avg;for(i=0;i<N;i+) printf("

27、;Please enter the data of the %d-th student:n",i);printf("name:");scanf("%s",);printf("sex:");scanf("%s",stdi.sex);if(stdi.sex0='m'|stdi.sex0='M')ml+=1;elsefml+=1;printf("score:");scanf("%d",&stdi.score);su

28、m+=stdi.score;avg=sum/N;printf("The number of male students:%dn",ml);printf("The number of female students are:%dn",fml);printf("The average scores are:%.2fn",avg);一、选择题1. A2. C3. D6. A7. D二、填空题1 . (1) high=mid-1 (2) low=mid+1 2 s3. (1) max=xij (2) max三、写出以下程序的运行结果1 . 6

29、252. Qian,p,95,923. 24. A 5. C(1) int m (2)m%i=0 (3) return4. 125. h=8四、编程题1. . #include "stdio.h void main() int prime(int);int x;精彩文档实用标准文案printf("nPlease input an integer:"); scanf("%d",&x);if(prime(x)printf("n%d is prime.n",x);elseprintf("n%d is not pr

30、ime.n",x);int prime(int n) int flag=1,i;for(i=2;i<=n-1 && flag=1;i+) if(n%i=0) flag=0;return(flag);2. #include "stdio.h"void delask(char a口) int i,j;char b80;for(i=j=0;ai!='0'i+)if(ai!='*') while(ai!='0')bj=ai;j+;i+; break; bj='0'for(i=0;bi!=

31、'0'i+)ai=bi;ai='0'void main() char s80;printf("Please enter a string:n");scanf("%s",s);delask(s);printf("%sn",s);3. #include "stdio.h"struct date int day;int month;int year;精彩文档实用标准文案);int days(struct date dt) int y,m,d,ds12=31,28,31,30,31,30,3

32、1,31,30,31,30,31,i,s=0;y=dt.year;m=dt.month;d=dt.day;if(y%4=0 && y%100!=0|y%400=0)ds1=29;/*计算每月的天数是本年第几天*/switch(m) case 1:for(i=0;i<m-1;i+)s+=dsi;s+=d;break;case 2:for(i=0;i<m-1;i+)s+=dsi;s+=d;break;case 3:for(i=0;i<m-1;i+)s+=dsi;s+=d;break;case 4:for(i=0;i<m-1;i+)s+=dsi;s+=d;br

33、eak;case 5:for(i=0;i<m-1;i+)s+=dsi;s+=d;break;case 6:for(i=0;i<m-1;i+)s+=dsi;s+=d;break;case 7:for(i=0;i<m-1;i+)s+=dsi;s+=d;break;case 8:for(i=0;i<m-1;i+)s+=dsi;s+=d;break;case 9:for(i=0;i<m-1;i+)s+=dsi;精彩文档实用标准文案s+=d;break;case 10:for(i=0;i<m-1;i+)s+=dsi;s+=d;break;case 11:for(i=0

34、;i<m-1;i+)s+=dsi;s+=d;break;case 12:for(i=0;i<m-1;i+)s+=dsi;s+=d;break;return (s);void main() struct date ymd;int dys;printf("Input year month and dayn");scanf("%d,%d,%d",&ymd.year,&ymd.month,&ymd.day);dys=days(ymd);printf("Today is the first %d days in the

35、 middle of this year.n",dys); 习题九一、选择题1. A 2, D 3.A 4. D 5. B 6.A二、写出以下程序的运行结果1 . 102. 911113. *4. 125. 86. 111213三、编程题1 . #include "stdio.h"#define N 10float fmax=0,fmin=0;float average(float fscore,int n) int i;float faver,fsum=fscore0;精彩文档实用标准文案fmax=fmin=fscore0;for(i=1;i<n;i+)(

36、if(fscorei>fmax)fmax=fscorei;else if(fscorei<fmin) fmin=fscorei;fsum+=fscorei;)faver=fsum/n;return (faver);)void main() float fave,fnumbN;int i;for(i=0;i<N;i+)scanf("%f",&fnumbi);fave=average(fnumb,N);printf("max=%.2f min=%.2f average=%.2fn",fmax,fmin, fave);)2 .此题有误

37、,用宏定义较难实现.以下程序仅供参考#include "stdio.h"void main() char strg30="C Language Program",c;int i=0;while(c=strgi)!='0') i+;if(c>='a' && c<='z')c=c-32;elseif(c>='A' && c<='Z')c=c+32;printf("%c",c);)printf("

38、n");)3 . #include "stdio.h"#include "math.h"#define S(a,b,c) (a+b+c)/2)#define AREA(a,b,c) sqrt(S(a,b,c)*(S(ahc)-a)*(S(a,b,c)-b)*(S(a,b,c)-c) void main() float a,b,c;printf("Please input a,b,c:");scanf("%f,%f,%f",&a,&b,&c);精彩文档实用标准文案if (a+b>

39、;c && a+c>b && b+c>a)printf("%.2fn",AREA(a,b,c); elseprintf("It is not a triangle!n");习题十1 .B2.D3.D46.A7.A8.C911,A12.B13.C14、选择题D5.CD10.AA15.C104.8二、写出以下程序的运行结果1. 212.034893438. 4 4 4 45 6 7 8 9 105. CBADGFE 6. 30,307. The data:i=5 c=B三、编程题1 . #include <s

40、tdio.h>#include <string.h> void fun(char *s,int *a,int *b) while(*s!='0') if(*s>=65 && *s<=90)*a+=1; /*可用(*a)+; */if(*s>=97 && *s<=122)*b+=1; /*可用(*b)+; */s+;void main() char s100;int upper=0,lower=0;printf("请输入一串字符:n");gets(s);fun(s,&upper,

41、&lower);printf("upper=%d,lower=%dn",upper,lower);2. #include <stdio.h>void fun(int *p1,int *p2) int p;p=*p1;*p1=*p2;精彩文档实用标准文案*p2=p;)void main() int a,b,*p11,*p22;scanf("%d,%d",&a,&b); p11=&a;p22=&b;if(a<b) fun(p11,p22); printf("%d,%dn",a,b);)一、选择题1. B26. C7.D3. B4.C8. A9C5D10this_is_a_test二、写出以下程序的运行结果1 . 1,2,3,0,0,123,0,0,10 20.010000三、编程题1 . #include "stdio.h"#include "stdlib.h"void main() FILE *fp;char ch;if

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论