How create BMI calculator and check whether the weight is normal or overweight or underweight in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>
 
float BMI(float weight, float height) {
    return weight / (height * height);  
}

int main() {
    float weight = 100.00; // kg
    float height = 1.95; // meter
    float bmi = BMI(weight, height);
   
    printf("BMI index is : %.2f\n", bmi);
   
    if (bmi < 15)  {  
        printf("Starvation\n");  
    }  
    else if (bmi >= 15.1 && bmi <= 17.5) {  
        printf("Anorexic\n");  
    }  
    else if (bmi >= 17.6 && bmi <= 18.5) {  
        printf("Underweight\n");  
    }  
    else if (bmi >= 18.6 && bmi <= 24.9) {  
        printf("Ideal\n");  
    }  
    else if (bmi >= 25 && bmi <= 25.9) {  
        printf("Light Overweight\n");  
    } 
    else if (bmi >= 26 && bmi <= 29.9) {  
        printf("Overweight\n");  
    }   
    else if (bmi >= 30 && bmi <= 30.9) {  
        printf("Obese\n");  
    }  
    else if (bmi >= 40) {  
        printf("Morbidly Obese\n");  
    }  
   
   return 0;
}
          
            
            
            
/*
run:
            
BMI index is : 26.30
Overweight
         
*/

 



answered Jul 13, 2020 by avibootz
edited Jul 13, 2020 by avibootz
...