# Body Mass Index Codechef Solution

Body Mass Index Codechef Solution: Hello coders, today we are going to solve Body Mass Index Codechef Solution.

## Problem

You are given the height HH (in metres) and mass MM (in kilograms) of Chef. The Body Mass Index (BMI) of a person is computed as MH2MH2. Report the category into which Chef falls, based on his BMI:

• Category 1: Underweight if BMI ≤18≤18
• Category 2: Normal weight if BMI ∈{19∈{19, 2020,……, 24}24}
• Category 3: Overweight if BMI ∈{25∈{25, 2626,……, 29}29}
• Category 4: Obesity if BMI ≥30≥30

### Input:

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

### Output:

For each testcase, output in a single line, 1,2,31,2,3 or 44, based on the category in which Chef falls.

### Constraints

• 1≤T≤2∗1041≤T≤2∗104
• 1≤M≤1041≤M≤104
• 1≤H≤1021≤H≤102
• Its guaranteed that H2H2 divides MM.

```3
72 2
80 2
120 2
```

```1
2
4
```

### Explanation:

Case 1: Since MH2=7222=18MH2=7222=18, therefore person falls in category 11.

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

Case 3: Since MH2=12022=30MH2=12022=30, therefore person falls in category 44.

## Body Mass Index – CodeChef Solution in JAVA

```import java.util.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int T;
T = sc.nextInt();
while(T-->0){
int M=0, H=0;
int BMI=0;
M = sc.nextInt();
H = sc.nextInt();
BMI = M/(H*H);
if(BMI<=18){
System.out.println("1");
}
else if(BMI>18 && BMI<=24){
System.out.println("2");
}
else if(BMI>24 && BMI<=29){
System.out.println("3");
}
else{
System.out.println("4");
}
}
}
}```

## Body Mass Index – CodeChef Solution in CPP

```#include <iostream>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int m,h,k;
cin>>m>>h;
k=m/(h*h);
if(k<=18){
cout<<"1\n";
}
else if(k>=19 && k<=24 ){
cout<<"2\n";
}
else if(k>=25 && k<=29){
cout<<"3\n";
}
else if(k>=30){
cout<<"4\n";
}
}
return 0;
}```

## Body Mass Index- CodeChef Solution in Python

```import math
for test in range(int(input())):
weight,height = list(map(int,input().split(" ")))
if ((weight/(height**2)))>=30:
print("4")
elif ((weight/(height**2)))>=25:
print("3")
elif ((weight/(height**2)))>=19:
print("2")
elif ((weight/(height**2)))<=18:
print("1")```

Disclaimer: The above Problem (Body Mass Index) is generated by CodeChef but the solution is provided by Chase2learn.This tutorial is only for Educational and Learning purpose.

Sharing Is Caring