C语言入门项目——BMI指数计算器
生活随笔
收集整理的這篇文章主要介紹了
C语言入门项目——BMI指数计算器
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
本文帶你分析簡單代碼片段。
/*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);//計(jì)算BMI指數(shù)Height_Square = pow(Height,2); //pow函數(shù)在math.h頭文件中 BMI = Weight / Height_Square;//判斷體重與身高是否>0if (Height > 0 && Weight > 0){printf("您的BMI指數(shù):%.2f。", BMI);if (BMI < 18.5){printf("您偏瘦。");}else if (BMI <= 24.9){printf("您的BMI指數(shù)正常。");}else{printf("您超重。");}}else{printf("輸入的數(shù)值必須大于0。三秒后暫停。\n");}//我們希望窗口不要立即關(guān)閉Sleep(3000);//延遲三秒 頭文件windows.hsystem("cls");//清屏stdlib.hsystem("pause");//暫停return 0; }本文代碼倉庫:https://gitee.com/linshu-gitee/bmi-calculator
總結(jié)
以上是生活随笔為你收集整理的C语言入门项目——BMI指数计算器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jQuery淘宝服饰精品案例
- 下一篇: 谷歌 | 最新110亿参数的T5模型17