云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 程序设计基础——基于C语言(第2版) 课后习题参考答案

程序设计基础——基于C语言(第2版) 课后习题参考答案

  • 62 次阅读
  • 3 次下载
  • 2025/5/6 4:43:29

#include #include void main() {

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 #include void main() {

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 void main() {

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 #include void main() {

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 #include void main() {

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 void main() {

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 void main()

{

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 void main() {

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 #include void main() {

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 void main() {

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 #define EPS 1e-7 void main() {

int n;

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

#include #include void main() { 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 #include void main() { 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

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com