❶ c語言程序設計,身高的計算。請各位幫忙看看我的程序,多謝了!
//順序不對
#include<stdio.h>
int main()
{
char sex,sports,diet;
float faheight,moheight,height;
printf("faheight="); //輸入的單位以公斤計算
scanf("%f", &faheight); //輸入的單位以公斤計算
printf("moheight=");
scanf("%f", &moheight);
printf("Male or Famale?Please input 'M' or 'F':");
scanf("%1s", &sex);
switch(sex)
{
case'F':height=(faheight+moheight)*0.54;break;
case'M':height=(faheight*0.923+moheight)/2;break;
}
printf("Do you like sports?please input'Y' or 'N':");
scanf("%1s", &sports);
switch(sports)
{
case'Y':height=height*(1.02);break;
case'N':height=height;break;
}
printf("Do you have good diet and habits?please input'Y' or 'N':");
scanf("%1s", &diet);
//分析判斷預測
switch(diet)
{
case'Y':height=height*(1.015);break;
case'N':height=height;break;
}
printf("\nmy height is:%.3f",height);
return 0;
}
❷ c語言編程實現根據某人的身高和體重判斷其身體指數
很簡單,只是需要接受兩個鍵盤輸入的值,做一個自定義條件判斷輸出不同狀態。這應該是老師給你的作業,目的還是訓練你自己,我們幫你完成對你沒什麼好處。
// 以下是參考
//一個簡單的標准:身體指數與體重、身高的關系為: 身體指數 t=w/(h*h);其中w為體重,h為身高 當t<18時,偏瘦。 當18<=t<25時,正常體重。 當25<=t<27時,超重。 當t>=27時,肥胖。
int main()
{
int t = 0;
float h = 0.0, w = 0.0;
scanf("請輸入你的體身高(單位:m)和體重(單位:kg):%f%f", &h, &w);
t = w / (h * h);
if (t < 18)
{
printf("偏瘦!");
}
else if (t >= 18 && t <25)
{
printf("正常體重!");
}
else if (t >= 25 && t < 27)
{
printf("超重!");
}
else if (t >= 27)
{
printf("肥胖!");
}
return 0;
}
個性簽名:3011
❸ c語言編程,身高預測
問題較多,幫你改了,再試試
int
main()
{
double
f,m,y;
int
f,m,y,n;
char
sex,sports,diet;
printf("請輸入父親身高:");
scanf("%lf",&f);
printf("請輸入母親身高:");
scanf("%lf",&m);
fflush(stdin)
;
printf("sex(f
,
m):");
scanf("%c",&sex);
fflush(stdin)
;
printf("sports(y
,
n):");
scanf("%c",&sports);
fflush(stdin)
;
printf("diet(y
,
n):");
scanf("%c",&diet);
//scanf("%lf\n",&y);
這句應該沒用!
if
(sex=='m'
)
y=(f+m)*0.54;
else
//
if
(sex=='f'
)
非男即女,這個if也沒用
y=(f*0.923+m)/2;
if
(sports=='y')
y=y*(1+0.02);
if
(diet=='y')
y=y*(1+0.015);
printf("y=%lfcm\n",y);
return
0;
}
❹ C語言編程題:輸入某人的身高(以厘米為單位,如174cm),將身高(以米為單位,如1.74m)輸出在屏幕上
//功能描述:1.計算人體指數
//體指數計算公式:t=w/h^2
//輸入參數:
//1.w:體重(公斤),數據類型為整型;
//2.h:身高(厘米),數據類型為整型;
//完成時間:2015年3月24日
//============================================//
//==========子函數floatcountBodyIndex(intbodyWeight,intbodyheight)
#include<stdio.h>
#include<stdlib.h>
floatcountBodyIndex(intbodyWeight,intbodyHeight)
{
//先對調用的參數進行檢查
if(bodyWeight<=0&&bodyHeight<=0)
{
printf("輸入的體重或身高錯誤,請檢查! ");
}
else
{
//將輸入的身高、體重、體指數輸出到屏幕上
printf("體重:%d(斤) ",bodyWeight*2);
printf("身高:%.2f ",bodyHeight/100.0);
}
return(bodyWeight*2)/(bodyHeight/100.0);
}
//==========主函數intmain(void)
intmain(void)
{
intbodyWeight,bodyHeight;
floatbodyIndex;printf("請輸入體重(公斤),身高(厘米): ");
scanf("%d%d",&bodyWeight,&bodyHeight);bodyIndex=countBodyIndex(bodyWeight,bodyHeight);
printf("體指數是:%.2f。 ",bodyIndex);system("pause");return0;
}
❺ C語言關於身高的
你這個是兩個程序吧,問題很多啊,你看下我改的吧。
第一個程序:
#include <stdio.h>
int main() {
float sex, woman, man, faheight, moheight;
char sport, diet;
scanf (" %d %f %f %c %c", &sex, &faheight, &moheight, &sport, &diet);
printf("輸入1表示女性0表示男性,父親身高,母親身高, 是否喜歡運動(Y / N), 是否有良好飲食習慣(Y / N)");
if (sex == 0, sport == 'N', diet == 'N') {
man = (faheight + moheight) * 0.54;
printf("man = % f", man);
} else if (sex == 0, sport == 'Y', diet == 'N') {
man = ((faheight + moheight) * 0.54) * (1 + 2. / 100);
printf("man = % f", man);
} else if (sex == 0, sport == 'Y', diet == 'Y') {
man = ((faheight + moheight) * 0.54) * (1 + 2. / 100) * (1 + 1.5 / 100);
printf("man = % f", man);
}
if (sex == 1, sport == 'N', diet == 'N') {
woman = (faheight + 0.923 + moheight) / 2;
printf("woman = % f", woman);
} else if (sex == 1, sport == 'Y', diet == 'N') {
woman = ((faheight + 0.923 + moheight) / 2) * (1 + 2 / 100);
printf("woman = % f", woman);
} else if (sex == 1, sport == 'Y', diet == 'Y') {
woman = ((faheight + 0.923 + moheight) / 2) * (1 + 2 / 100) * (1 + 1.5 / 100);
printf("woman = % f", woman);
}
return 0;
}
第二個程序:
#include"stdio.h"
int main() {
char c;
int letters = 0, space = 0, digit = 0, other = 0;
printf("輸入一行字元: \n");
while ((c = getchar()) != '\n') {
if ('c' > 'a' && 'c' < 'z' || 'c' > 'A' && 'c' < 'Z')
letters++;
else if ('c' > '0' && 'c' < '9')
digit++;
else if ('c' == ' ')
space++;
else other++;
}
printf(" % d, % d, % d, % d", letters, digit, space, other);
return 0;
}
❻ C語言編程關於身高預測問題,請大神幫忙看看哪裡錯了急急急急!
#include<stdio.h>
void main()
{
char sex,sports,diet;
float faHeight,moHeight,chHeight = 0;
scanf("%c,%c,%c,%f,%f",&sex,&sports,&diet,&faHeight,&moHeight);
if(sex == 'M')
chHeight = (faHeight + moHeight)*0.54;
else if(sex == 'F')
chHeight = (faHeight*0.923+moHeight)/2;
if(sports == 'Y')
chHeight = chHeight * 1.02;
if(diet == 'Y')
chHeight = chHeight * 1.015;
printf("height = %f",chHeight);
}
手打不容易,你寫的程序稍後給你分析,你先用我這個應急吧~~
❼ 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>
intmain()
{
doublebmi,w,h;
printf("請輸入你的體重(kg):");
scanf("%lf",&w);
printf("請輸入你的身高(m):");
scanf("%lf",&h);
bmi=w/(h*h);
printf("你的BMI指數=%.2lf 您的體重:",bmi);
if(bmi<19)
{
printf("偏低! ");
}
elseif(bmi>=19&&bmi<25)
{
printf("健康 ");
}
elseif(bmi>=25&&bmi<30)
{
printf("超重! ");
}
elseif(bmi>=30&&bmi<39)
{
printf("嚴重超重! ");
}
elseif(bmi>=40)
{
printf("極度超重! ");
}
printf("體重指數: 19以下體重偏低 19-25健康體重 25-30超重 30-39嚴重超重 40及40以上極度超重 ");
return0;
}
❾ 用C語言編寫身高單位轉換:鍵盤輸入一個英制身高(幾英尺幾英寸),計算對應的公
你是問英制轉公制:
一、公式1英尺=12英寸,1英寸=2.54厘米。
二、定義兩個浮點數變數表示英尺和英寸,輸入後,套上面公式算即可。
比如:
#include<stdio.h>
int main()
{
float feet,inch,meter;
printf("輸入身高英尺 英寸:");
scanf("%f%f",&feet,&inch);
meter=(feet*12+inch)*2.54*100;
printf("轉換後%f米\n",meter);
return 0;
}
//ps:手機打代碼,自行退格調整對齊。
❿ 身高測量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;
}
//純手打,望採納,有問題追問