第一范文网 - 专业文章范例文档资料分享平台

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

来源:用户分享 时间:2025/7/25 3:32:49 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

#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;

程序设计基础——基于C语言(第2版) 课后习题参考答案.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c4snj203idx23x6i11q62_4.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top