100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > C语言入门项目——BMI指数计算器

C语言入门项目——BMI指数计算器

时间:2021-01-26 05:29:39

相关推荐

C语言入门项目——BMI指数计算器

本文带你分析简单代码片段。

/*UTF-8*///BMI.h#include<stdio.h>#include<math.h> #include<stdlib.h> #include<windows.h>double Height;double Weight; double Height_Square;double BMI;

这里包含了头文件,声明了变量。

/*UTF-8*///BMI.c#include"BMI.h"int main(void){printf("您的身高(米)?\n");scanf("%lf",&Height); printf("您的体重(公斤)?\n");scanf("%lf",&Weight);//计算BMI指数Height_Square = pow(Height,2); //pow函数在math.h头文件中 BMI = Weight / Height_Square;//判断体重与身高是否>0if (Height > 0 && Weight > 0){printf("您的BMI指数:%.2f。", BMI);if (BMI < 18.5){printf("您偏瘦。");}else if (BMI <= 24.9){printf("您的BMI指数正常。");}else{printf("您超重。");}}else{printf("输入的数值必须大于0。三秒后暂停。\n");}//我们希望窗口不要立即关闭Sleep(3000);//延迟三秒 头文件windows.hsystem("cls");//清屏stdlib.hsystem("pause");//暂停return 0;}

本文代码仓库:/linshu-gitee/bmi-calculator

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。