编写程序计算身高

编写程序计算身高,第1张

#include <stdio.h>

int main(void)

{

    float faHeight,moHeight,chHeight

    printf("父亲的身高(cm):")

    scanf("%f",&faHeight)

    printf("母亲的身高(cm):")

    scanf("%f",&moHeight)

    printf("孩子的性别(M/F):")

    getchar()

    if(getchar() == 'M'){

        chHeight = (faHeight + moHeight ) * 0.54

    }else if(getchar() == 'F'){

        chHeight = (faHeight * 0.923 + moHeight)/2

    }else{

        chHeight = 0

    }

    getchar()

    printf("是否喜爱体育锻炼(Y/N):")

    if(getchar() == 'Y'){

        chHeight *= 1.02

    }

    getchar()

    printf("是否有良好的卫生饮食习惯(Y/N):")

    if(getchar() == 'Y'){

        chHeight *= 1.015

    }

    printf("预测的身高:%dcm\n",(int)(chHeight + 0.5))

    return 0

}

#include<stdio.h>

int main()

{

float faheight,moheight,a

char sex,sport,habit

printf("Please input: Father's height(space)Mother's height(cm)\n")

scanf("%f %f",&faheight,&moheight)//%f

{

getchar()//接收'\n'

printf("IF THE BABY IS A BOY?(y or n)\n")

sex=getchar()

if(sex=='y')

a=(faheight+moheight)*1.0*0.54

if(sex=='n')

a=(faheight*0.923+moheight)/2

getchar()

}

{

printf("DOES HE/SHE LIKE SPORTS?(y or n)\n")

sport=getchar()

if(sport=='y') 

a=a*1.02

if(sport=='n')

a=a*1.0

getchar()

}

{

printf("DOES HE/SHE HAVE GOOD HABITS?(y or n)\n")

habit=getchar()

if(habit=='y')

a=a*1.015

if(habit=='n')

a=a

getchar()

}

printf("Height=%.2f cm",a)

return 0

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/11296713.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-15
下一篇2023-05-15

发表评论

登录后才能评论

评论列表(0条)

    保存