當前位置:首頁 » 編程語言 » c語言孩子的身高
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言孩子的身高

發布時間: 2023-01-24 18:46:27

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(&#39;m&#39;==sex |&#39;M&#39;==sex) h=(hf+hm)*0.54; else h=(hf*0.923+hm)/2; if((&#39;y&#39;==sports |&#39;Y&#39;==sports)&&(&#39;y&#39;==diet |&#39;Y&#39;==diet)) h=(1+0.02+0.015)*h; else if(&#39;y&#39;==sports |&#39;Y&#39;==sports) h=(1+0.02)*h; else if(&#39;y&#39;==diet |&#39;Y&#39;==diet) h=(1+0.015)*h; else h=h; printf("The height of the boy is %f ",h);}