下载此文档

哈工大C语言实验题.docx


文档分类:IT计算机 | 页数:约44页 举报非法文档有奖
1/44
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/44 下载此文档
文档列表 文档介绍
Revised by Hanlin on 10 January 2021
哈工大C语言实验题
Q308.(10分)第5章 实验2:体型判断。
医务工作者经广泛的调查和统计分析,根据身高与体重因素给出了以下按“体指数”进行体型判断的方法。体指数计算公式是:
t = w /(h*h)
其中:t是体指数;w是体重,其单位为千克;h是身高,其单位为米。根据给定的体指数t计算公式,可判断你的体重属于何种类型:
当 t<18 时,为低体重;
当 18≤t<25 时,为正常体重;
当 25≤t<27 时,为超重体重;
当 t≥27 时,为肥胖。
****输入提示信息格式:"Please enter h,w:\n"
****输入数据格式要求:"%f,%f"(先读入身高,再读入体重,身高以米读入,体重以千克读入)
****输出数据格式要求:
当 t<18 时,输出:"Lower weight!\n"
当 18≤t<25 时,输出:"Standard weight!\n"
当 25≤t<27 时,输出:"Higher weight!\n"
当 t≥27 时, 输出:"Too fat!\n"
#include <>
#include <>
main()
{
float t,w,h;
printf("Please enter h,w:\n");
scanf("%f,%f",&h,&w);
t = w/(h*h);
if(t<18)
printf("Lower weight!\n");
else if(t>=18&&t<25)
printf("Standard weight!\n");
else if(t>=25&&t<27)
printf("Higher weight!\n");
else
printf("Too fat!\n");
return 0;
}
Q586.(
10分)编写一个程序,输入年份和月份,判断该年是否是闰年,并根据给出的月份判断是什么季节和该月有多少天(闰年的条件是年份能被4整除但不能被100整除,或者能被400整除;规定3~5月为春季,6~8月为夏季,9~11月为秋季,1、2和12月为冬季)。
**输入格式要求:"%d,%d" 提示信息:"Please enter year,month:"
**输出格式要求:"%d is leap year\n" "%d is not leap year\n" "The season is spring/summer/autumn/winter" "The number of days of this month is %d\n"
程序运行示例如下:
实例1:
Please enter year,month:2012,11
2012 is leap year
The season is autumn
The number of days of this month is 30
实例2:
Please enter year,month:2013,12
2013 is not leap year
The season is winter
The number of days of this month is 31
#include <>
#include <>
main()
{
int year=0,leap=0,mon=0,day=0;
printf("Please enter year,month:");
scanf("%d,%d",&year,&mon);
if((year%100!=0&&year%4==0)||(year%100==0&&year%400==0)){
printf("%d is leap year\n",year);
leap=1;
}
else
printf("%d is not leap year\n",year);
switch(mon)
{
case 1:
case 2:
case 12:printf("The season is winter\n");
break;
case 3:
case 4:
case 5:printf("The season is spring\n");
break;
case 6:
case 7:
case 8:printf("The season is summer

哈工大C语言实验题 来自淘豆网www.taodocs.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数44
  • 收藏数0 收藏
  • 顶次数0
  • 上传人永旭
  • 文件大小757 KB
  • 时间2021-05-05