C语言程序设计 (何钦铭 颜晖 著) 高等教育出版社第三章 课后答案_第1页
C语言程序设计 (何钦铭 颜晖 著) 高等教育出版社第三章 课后答案_第2页
C语言程序设计 (何钦铭 颜晖 著) 高等教育出版社第三章 课后答案_第3页
C语言程序设计 (何钦铭 颜晖 著) 高等教育出版社第三章 课后答案_第4页
C语言程序设计 (何钦铭 颜晖 著) 高等教育出版社第三章 课后答案_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、练习32#include <stdio.h>void main()float x;int y;printf("Please Input x: ");scanf("%f",&x);if(x>0)y=1;else if(x=0)y=0;else y=-1;printf("sign(%f)=%dn",x,y);练习33#include <stdio.h>void main()int i,letter,digit,space,other;char ch;letter=digit=space=other=0

2、;printf("Please Input 15 charactors: ");for(i=1;i<=15;i+)ch=getchar();if(ch=' ' | ch='n')space+;else if(ch>='0' && ch<='9')digit+;else if(ch>='A' && ch<='Z') | (ch>='a' && ch<='z')l

3、etter+;else other+;printf("letters=%d,digits=%d,spaces=%d,others=%dn",letter,digit,space,other);练习36#include <stdio.h>void main()char ch;printf("Please Input grade (AE): ");ch=getchar();switch(ch)case 'A':printf("The score is between 90-100.n");break;case

4、'B':printf("The score is between 80- 89.n");break;case 'C':printf("The score is between 70- 79.n");break;case 'D':printf("The score is between 60- 69.n");break;case 'E':printf("The score is between 0- 59.n");break; default: prin

5、tf("Input error!n");break;练习37#include <stdio.h>void main()int i,ch;float price;for(i=1;i<=5;i+) printf("1 applesn"); printf("2 pearsn"); printf("3 orangesn"); printf("4 grapesn"); printf("0 Exitn"); printf("Please choice(04):

6、 ");scanf("%d",&ch);if(ch=0)break; switch(ch)case 1:price=3.0;break;case 2:price=2.5;break;case 3:price=4.1;break;case 4:price=10.2;break;default: price=0.0;break;printf("The price is %.1f.n",price);练习38#include <stdio.h>void main()int year;printf("Please inpu

7、t a year: ");scanf("%d",&year);if(year%4=0 && year%100!=0) | (year%400=0)printf("Yes.n");else printf("No.n");练习39#include <stdio.h>void main()int i,n,num=0;float score,total=0;printf("Please input numbers of student: ");scanf("%d&qu

8、ot;,&n);for(i=1;i<=n;i+) printf("Please input score #%d(0100): ",i);scanf("%f",&score);if(score>=60)num+;total=total+score;printf("The average score is %.2f.n",total/n); printf("The numbers of passing is %d.n",num);练习310#include <stdio.h>vo

9、id main()double x,y;printf("Please input x: ");scanf("%lf",&x);if(x>15)y=2.5*x-10.5;elseif(x<0)y=0;else y=4*x/3;printf("y=f(%lf)=%lfn",x,y);习题31#include <stdio.h>#include <math.h>void main()double a,b,c,s,area,perimeter;printf("Please input a,

10、b,c. : ");scanf("%lf%lf%lf",&a,&b,&c);if(a+b>c && b+c>a && a+c>b && a>0 && b>0 && c>0)s=(a+b+c)/2;area=sqrt(s*(s-a)*(s-b)*(s-c);perimeter=2*s;printf("perimeter=%lf,area=%lfn",perimeter,area);else printf(&q

11、uot;These sides do not correspond to a valid triangle.n");习题32#include <stdio.h>#include <math.h>void main()double salary,tax,rate;printf("Please salary.: ");scanf("%lf",&salary);if(salary<=850)rate=0;else if(salary<=1350)rate=5;else if(salary<=2850)

12、rate=10;else if(salary<=5850)rate=15;else rate=20;tax=rate*(salary-850)/100;printf("These tax is %.2lf.n",tax);习题34#include <stdio.h>void main()int i,n,numa,numb,numc,numd,nume;float score,total=0;numa=numb=numc=numd=nume=0;printf("Please input numbers of student: ");sca

13、nf("%d",&n);for(i=1;i<=n;i+) printf("Please input score #%d(0100): ",i);scanf("%f",&score);if(score<60)nume+;else if(score<70)numd+;else if(score<80)numc+;else if(score<90)numb+;else if(score<=100)numa+;total=total+score;printf("The average score is %.2f.n",total/n); printf("The numbers of grade A(90100) is %d.n",numa); printf("The numbers of grade B(8089) is %d.n",numb); printf("The numbers of grade C(7079) is %d.n",numc); printf("The numbers of grade D(6069) is %d.n",numd); printf(&

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论