Ⅰ c语言编写一个儿童身高程序
题目这个 7-8 岁、8-9 岁,意味着可能输入小数,因此将年龄定义为实型。
实型由于精度问题,不能直接用 “ == ” 进行比较。采用计算误差小于某一值的办法。
#include <stdio.h>
void main()
{
float y,h;
printf("请输入儿童年龄与身高(米):");
scanf("%f%f",&y,&h);
if(y<7 || y>10)
printf("不在检测范围 ");
else if(y>=7 && y<8)
printf("%s达标 ",(abs(h-1.3)>=1e-6)?"":"不");
else if(y>=8 && y<9)
printf("%s达标 ",(abs(h-1.35)>=1e-6)?"":"不");
else if(y>=9 && y<=10)
printf("%s达标 ",(abs(h-1.4)>=1e-6)?"":"不");
}
Ⅱ 身高测量c语言编程
#include <stdio.h>
void main()
{
char sex;
int f,m;
printf("测量人的性别(m/f):");
scanf("%c",&sex);
switch(sex)
{
case 'm':printf("%g",(1.7+1.6)*1.08/2);break;
case 'f':printf("%g",(1.7+1.6*0.923)/2);break;
default:printf("输入错误!");
}
return;
}
//纯手打,望采纳,有问题追问
Ⅲ 简单的c语言程序 关于父母的身高推测孩子的身高 并证明公式的准确性
只要公式没错,这个程序就是对的了,scanf("%.1f",&b);输入的时候其实可以直接scanf("%f",&b);这样更好些。推荐用double比float要准些。
Ⅳ c语言的一道题,画流程图,该程序用于计算小孩身高(画出流程图、粘贴代码和程序结果)
#includevoid main(){ float hf,hm,h; char sex,sports,diet; printf("Please type in the sex(M/F):"); scanf("%c",&sex); printf("Please type in the height of father:"); scanf("%f",&hf); printf("Please type in the height of mother:"); scanf("%f",&hm); printf("Do sports(Y/N):"); getchar(); ; ; ; ; ; ; ; ; ; ;//没特别的意思,只是消除回车键的影响 scanf("%c",&sports); printf("Have a diet(Y/N):"); getchar(); ; ; ; ; ; ; ; ; ; ; ;//没特别的意思,只是消除回车键的影响 scanf("%d",&diet); if('m'==sex |'M'==sex) h=(hf+hm)*0.54; else h=(hf*0.923+hm)/2; if(('y'==sports |'Y'==sports)&&('y'==diet |'Y'==diet)) h=(1+0.02+0.015)*h; else if('y'==sports |'Y'==sports) h=(1+0.02)*h; else if('y'==diet |'Y'==diet) h=(1+0.015)*h; else h=h; printf("The height of the boy is %f ",h);}