작성일 :

문제 링크

6825번 - Body Mass Index

설명

간단한 사칙연산 문제입니다.

입력으로 주어지는 몸무게와 키를 파싱한 후,
문제에 주어진 bmi 계산 식에 따라서 bmi 지수를 계산합니다.

계산한 bmi 지수의 수치에 대하여 조건문을 사용하여
과체중인지, 저체중인지, 보통인지를 판별한 후,

문제의 출력 형식에 맞추어 출력합니다.


Code

[ C# ]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
namespace Solution {
  class Program {
    static void Main(string[] args) {

      double.TryParse(Console.ReadLine(), out double w);
      double.TryParse(Console.ReadLine(), out double h);

      double bmi = w / Math.Pow(h, 2);

      string ans = "";
      if (bmi < 18.5) ans = "Underweight";
      else if (bmi >= 18.5 && bmi < 25) ans = "Normal weight";
      else if (bmi >= 25) ans = "Overweight";

      Console.WriteLine(ans);

    }
  }
}



[ C++ ]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  double w, h; cin >> w >> h;

  double bmi = w / pow(h, 2);

  string ans = "";
  if (bmi < 18.5) ans = "Underweight";
  else if (bmi >= 18.5 && bmi < 25) ans = "Normal weight";
  else if (bmi >= 25) ans = "Overweight";

  cout << ans << "\n";

  return 0;
}