C语言程序设计第二版第四章第七章课后答案.doc
《C语言程序设计第二版第四章第七章课后答案.doc》由会员分享,可在线阅读,更多相关《C语言程序设计第二版第四章第七章课后答案.doc(14页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、1、输入函数scanf的参数错误,应该为:scanf(%f,&k); 2、|1234 1234 | 3、ff10 4、1,3,1 5、原字符串左边加空格再加字符串本省,字符个数总和为5个6、scanf(%d,%d,%c,%c,&a1,&a2,&c1,&c2); 7、printf(a+b=%dn,a+b); printf(a-b=%dn,a-b); printf(a*b=%dn,a*b); printf(a/b=%dn,a/b); printf(float)a/b=%fn,(float)a/b); printf(a%b=%dn,a%b); 8、void main() float r; float
2、 s,c; printf(please input the number:); scanf(%f,&r); if(r=0) s = 3.14*r*r; c = 2*3.14*r; printf(s = %f, c = %fn,s,c); else printf(you input number is error!); 9void main() int n; printf(please input the number:); scanf(%d,&n); if(n=100 & n c | a+c b | b+c a) s = (a+b+c)/2; Area = sqrt(s*(s-a)*(s-b)
3、*(s-c); printf(%fn,Area); else printf(you input the number is error!n); 习题4 1:0 2:20 3: (x20)|(x-100) 4: *a=25,b=14,c=16* 5: 37 6: if(a=b) printf(1); else printf(2); 7、#include void main() char a,b,t1,t2; scanf(%c,%c,&a,&b); t1=ab?a:b; t2=ab?a:b; if(t1-t2)%2=0)printf(%c,%c,a+1,b+1); else printf(%c,%
4、c,a-1,b-1); getch(); 8、#include void main() int temp1=0,temp2=0,x,y,i=1; printf(Please input (x,y): ); scanf(%d,%d,&x,&y); while(i*y) shang=%d,yushu=%d,x,y,temp2,x-y*temp2); getch(); 9、#include void main() float x,y,m=0,n=0; scanf(%f,%f,&x,&y); n=(x-2)*(x-2); m=(y-2)*(y-2); if(m+n)=1) printf(%.3f,%.
5、3f)In the yuan,x,y); else printf(%.3f,%.3f)out of the yuan,x,y); getch(); 10、#include void main() int temp=0,month,year; printf(Please input (year,month): ); scanf(%d,%d,&year,&month); if(year%400=0)|(year%4=0&year%100!=0) temp=1; if(month=2) if(temp)printf(%d year %d month have 29 ,year,month); els
6、e printf(%d year %d month have 28 ,year,month); else if(month%2=0) printf(%d year %d month have 30 ,year,month); else printf(%d year %d month have 31 ,year,month); getch(); 11、switch(a/10) case 5:m=4;break; case 4:m=3;break; case 3:m=2;break; case 2:m=1;break; default:m=5; 12、方法一:#include void main(
7、) int x,y; scanf(%d,&x); if(x-5) y=x-1; else if(x=0) y=x; else if(x0&x8) y=x+1; printf(%d,y); getch(); 方法二:#include void main() int x,y; scanf(%d,&x); if(x-5) if(x=0)y=x; float x,y,t;printf(Enter two number (x,y): );scanf(%f,%f,&x,&y);SWAP(x,y);printf(nnExchanged:x=%f,y=%f,x,y);getch();5、#includeint
8、 fib(int n)int p;if(n=0) p=0;else if(n=1) p=1;else p=fib(n-1)+fib(n-2);return p;void main()int n;printf(Please input fib: );scanf(%d,&n);printf(nnfibonacci=%d,fib(n);6、#includelong fac(int n)long f;if(n=0)f=1;elsef=n*fac(n-1);return f;void main()int m,n;long f;printf(Please input (m,n): );scanf(%ld,
9、%ld,&m,&n);f=fac(n+m)+fac(n);printf(nnfibonacci=%ld,f);7、#includevoid list()int i,j;for(i=1;i=9;i+) for(j=1;j=i;j+)printf(%d*%d=%d ,i,j,i*j);printf(n);void main()list();8、#includeint he(int n)int i,s=0;for(i=1;in;i+)if(n%i=0)s+=i;return s;void main()int i,j;for(i=1;i30000;i+)for(j=1;j30000;j+)if(he(
10、i)=j)&(he(j)=i)&(i!=j)printf(%d%d ,i,j);9、#include#define max 100struct worklong sid;char name15;workermax;int size=0;struct work *set_list()doprintf(nnPlease input (sid,name): );scanf(%ld,%s,&workersize.sid,workersize.name);size+;while(workersize-1.sid!=0);return worker;void paixu(struct work a)int
11、 i,j,k;long t;char v15;for(i=0;isize-1-2;i+)k=i;for(j=i;jaj.sid)k=j;if(k!=i)t=ai.sid; ai.sid=aj.sid; aj.sid=t;strcpy(v,ai.name);strcpy(ai.name,aj.name);strcpy(aj.name,v);for(i=0;i=size-2;i+)printf(sid: %ldtname:%snn,ai.sid,ai.name);getch();void select(struct work a)int i=0,found=1;long num;printf(In
12、put select sid: );scanf(%ld,&num);for(i=0;i=size-2;i+)if(ai.sid=num) found=0;printf(%ld: %s,num,ai.name);break;if(found)printf(nnNO this sid!);getch();void main()struct work *p;p=set_list();paixu(p);select(p);10、#includefloat jiecheng(int n)long s=1;int i;for(i=1;i=n;i+)s=s*i;return s;float chengfan
13、g(float x,int n)float s=1;int i;for(i=1;i=n;i+)s=s*x;return s;float f(float x,int n)float s=1,t=0;int i=1,j=-1;for(i=1;i=0 ak=temp break k=8(2) %s stri=Z cstri+26-a+ i+a4、/*题目:求一组成绩的平均分数以及高于平均分的成绩。*/#include#define max 100void main()float amax,s=0,average=0;int i,n;printf(Please input N: ); /*输入要处理元
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言程序设计 第二 第四 第七 课后 答案
限制150内