当前位置:首页 > 程序设计基础——基于C语言(第2版) 课后习题参考答案
#include
float r,s,l; scanf(\s=(float)PI*r*r; l=2*(float)PI*r;
printf(\}
输入:3
输出结果:r= 3.0,s=28.3 ,l=18.8 6.
#include
float x1,y1,x2,y2,x3,y3,a,b,c,p,s;
scanf(\a=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); b=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3)); c=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3)); p=(a+b+c)/2;
s=sqrt(p*(p-a)*(p-b)*(p-c)); printf(\}
输入:5 6 3 8 0 23
输出结果:Area=12.000013 习题4参考答案
4.1选择题。
1)D (2)A (3)A (4)C (5)C (6)B (7)B 4.2填空题。
1)261 (2)16 (3)0 (4)2,1 4.3编程题。
1) #include
float c,f;
printf(\输入华氏温度:\\n\); scanf(\%f\,&f); c=(f-32)*5/9;
printf(\摄氏温度为:%5.2f\\n\,c); }
8)B (9)C 10)A
( ( ((((2)
(3)
#include
char s1[10],s2[10],s[20];
printf(\please enter two string\\n\); gets(s1); gets(s2);
strcat(s1,s2);
printf(\%s\\n\,s1);
printf(\%d\\n\,strlen(s1)); }
#include
double x,y;
printf(\please enter two data:\\n\); scanf(\%lf%lf\,&x,&y);
printf(\%lf raised to %lf is %lf\\n\,x,y,pow(x,y)); }
习题5参考答案
1.填空题
(1) n=4 (2) 2*i-1 (3) 7 (4) ###### 2.#include
long m,n,a,b,s;
printf(\ scanf(\
printf(\ scanf(\ a=(m>n)?m:n; b=(m>n)?n:m; while (a%b!=0) {
s=a%b; a=b; b=s; }
printf(\
printf(\}
3.#include
{
int a,b,c,d,e;
printf(\ scanf(\ if (a/1000==0) {
printf(\ return; }
b=a/1000; e=a;
c=a00/100; d=a0/10;
if (b==e && c==d) printf(\ else
printf(\}
4.#include
int c;
int Num1,Num2,Num3,Num4; Num1=Num2=Num3=Num4=0; do {
c=getchar();
if ((c>='a' && c<='z') || (c>='A' && c<='Z')) Num1++;
else if (c>='0' && c<='9') Num2++;
else if (c==' ') Num3++; else
Num4++; }while(c!='\\n');
printf(\英文字母有%d个,数字有%d个,空格有%d个,其它字符有%d个。\\n\
}
5.#include
float a,b,c,disc,x1,x2,realpart,imagepart;
printf(\ scanf(\ printf(\ disc=b*b-4*a*c;
if (fabs(disc)<=1e-7)
printf(\ else
if (disc>1e-7) {
x1=(-b+sqrt(disc))/(2*a); x2=(-b-sqrt(disc))/(2*a);
printf(\ } else {
realpart=-b/(2*a);
imagepart=sqrt(-disc)/(2*a); printf(\
printf(\
printf(\ } }
6. #include
int i,j;
for (i=1;i<=5;i++) {
for (j=1;j<=i;j++) printf(\ printf(\ }
for (i=5;i>=1;i--) {
for (j=i;j>=1;j--) printf(\ printf(\ } }
7.#include
int n;
共分享92篇相关文档