ภาษาซี กับ โจทย์ คำนวณ BMI

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: ภาษาซี กับ โจทย์ คำนวณ BMI

ภาษาซี กับ โจทย์ คำนวณ BMI

โดย Aussadawut » 17/11/2018 7:34 pm

โจทย์ : คำนวณ BMI
cbmi.png
cbmi.png (29.27 KiB) Viewed 16084 times

โค้ด: เลือกทั้งหมด

#include<stdio.h>
main(){
        float weight=0,height=0,calbmi;
        printf("You weight :");
        scanf("%f",&weight);	// รับค่าน้ำหนัก
        printf("You height (m):");
        scanf("%f",&height);	// รับค่าส่วนสูง เมตร
        calbmi = weight/(height*height);	// คำควณ ค่า BMI
        printf("You BMI :%f\n",calbmi);
        if(calbmi < 18.5){	// ต่ำกว่าเกณฑ์
                printf("Underweight\n");
        }else if(calbmi <= 22.9){	// สมส่วน
                printf("slim\n");
        }else if(calbmi <= 24.9){ 	// น้ำหนักเกิน
                printf("Over weight\n");
        }else if(calbmi <= 29.9){ 	// โรคอ้วน
                printf("Obesity\n");
        }else{	// เกณฑ์ที่อันตราย
                printf("Dangerous\n");
        }
}
ตัวอย่างโปรแกรม ที่ใช้งานจริง คำนวณ BMI บนเว็บ
https://www.ecitepage.com/bmi.php

ข้างบน