资源描述:
《C语言程序设计答案.docx》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、C语言程序设计(第三版)黄保和江弋主编第一到四章编程题答案2.1#include#includevoidmain(){printf("%g",fabs(-6)+16.3*5.4);}2.2#include#includemain(){inta,b;printf("Inputa,b:");scanf("%d%d",&a,&b);if(a>b)printf("%g",sqrt(a));elseprintf("%g",sqrt(b));}2
2、.3#includemain(){floata;printf("Inputa:");scanf("%g",&a);printf("thesquareofa=%gtacubed=%g",a*a,a*a*a);}2.4#includemain(){floata,b,c,d,sum;printf("Inputa,b,c,d:");scanf("%f%f%f%f",&a,&b,&c,&d);sum=a+b+c+d;printf("%f",sum/4);}2.5#inclu
3、demain(){intn,a,b,c,d,e,s;printf("请输入一个五位数:");scanf("%d",&n);a=n%10;b=n/10%10;c=n/100%10;d=n/1000%10;e=n/10000;s=a+b+c+d+e;printf("%d",s);}3.2#includemain(){floatr,C,S;printf("Inputr:");scanf("%f",&r);C=2*3.14159*r;S=3.141459*r*r;printf(
4、"C=%.2ftS=%.2f",C,S);}3.3#includemain(){floatf,c;printf("请输入华氏温度:");scanf("%f",&f);c=5.0/9*(f-32);printf("摄氏温度为=%.2f",c);}3.4#include#includemain(){floata,b,c,S,p;printf("输入三角形的三条边长:");scanf("%f%f%f",&a,&b,&c);if(a+b>c&&b+c>a&&c
5、+a>b){p=(a+b+c)/2;S=sqrt(p*(p-a)*(p-b)*(p-c));printf("S=%f",S);}elseprintf("该三角形不存在");}3.5#includemain(){printf("AAaBB");printf("AAbBB");printf("AABB");printf("AArBB");printf("AAtBB");printf("AAvBB");printf("AA'BB");printf("AA"
6、BB");printf("AA\BB");printf("AA?BB");}3.6#includemain(){charzimu;printf("请输入小写英文字母:");scanf("%c",&zimu);zimu=zimu-32;printf("%c",zimu);}3.7#includemain(){chara,b,c;printf("请输入两个字符:");scanf("%ct%c",&a,&b);{c=a;a=b;b=c;}printf("%ct
7、%c",a,b);}3.8#include#includemain(){floatrate=3.25,capital,n,deposit;printf("请输入存款本金:");scanf("%f",&capital);printf("请输入存款期:");scanf("%f",&n);deposit=capital+capital*rate/100*n;printf("%lf",deposit);}3.9#include#includemain
8、(){floata,b,c=9;printf("请输入该销售员的销售额:");scanf("%f",&a);b=1000+a*c/100;printf("%f",b);}4.1#includemain(){inta;printf("请输入一个整数:");scanf("%d",&a);if(a%2==0)printf