Algorithm


 problem Link ;  https://www.codechef.com/problems/BMI 

Problem

Read problems statements in HindiMandarin ChineseVietnamese, and Bengali as well.

You are given the height  (in metres) and mass  (in kilograms) of Chef. The Body Mass Index (BMI) of a person is computed as ��2.

Report the category into which Chef falls, based on his BMI:

  • Category 1: Underweight if BMI ≤18
  • Category 2: Normal weight if BMI ∈{1920,24}
  • Category 3: Overweight if BMI ∈{2526,29}
  • Category 4: Obesity if BMI ≥30

###Input:

  • The first line of input will contain an integer, , which denotes the number of testcases. Then the testcases follow.
  • Each testcase contains a single line of input, with two space separated integers, �,�, which denote the mass and height of Chef respectively.

###Output: For each testcase, output in a single line, 1,2,3 or 4, based on the category in which Chef falls.

###Constraints

  • 1≤�≤2∗104
  • 1≤�≤104
  • 1≤�≤102
  • Its guaranteed that �2 divides .

Sample 1:

Input
 
Output
 
3
72 2
80 2
120 2
1
2
4

Explanation:

Case 1: Since ��2=7222=18, therefore person falls in category 1.

Case 2: Since ��2=8022=20, therefore person falls in category 2.

Case 3: Since ��2=12022=30, therefore person falls in category 4.

 

Code Examples

#1 Code Example with C Programming

Code - C Programming

 #include<stdio.h>
int main()
{
    int h,m,t,bmi;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d %d",&m,&h);
        bmi=(m/(h*h));
        if(bmi < =18 && bmi>0) printf("1\n");
        else if(bmi<=24) printf("2\n");
        else if(bmi < =29) printf("3\n">;
        else if(bmi>=30) printf("4\n");
    }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3
72 2
80 2
120 2

Output

x
+
cmd
1
2
4
Advertisements

Demonstration


CodeChef solution BMI  - Body Mass Index Codechef solution in C,C++

Previous
CodeChef solution SUPCHEF - The Preparations Codechef solution in C,C++
Next
CodeCherf solution FLOW010 - ID and Ship Codecherf solution in C,C++