Home »
.Net »
C# Programs
C# program to take height as input and print its category as Dwarf, Average, and Tall
C# program to input a height and print its (a person) category as Dwarf, Average, and Tall.
Submitted by Nidhi, on August 17, 2020
Here we will create a C# program that takes height as input and print its category as Dwarf, Average, and Tall.
- For the "Tall" height person we checked condition, height must be greater than 170 cm.
- For the "Average" height person we checked condition, height must be between 160 and 170 cm.
- For the "Dwarf" height person we checked condition, height must be less than 160 cm.
Program:
The source code to print the height category in C# is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
//Program to take height as input and print
//its category as Dwarf, Average, and Tall.
using System;
class program
{
public static void Main()
{
int height=0;
Console.WriteLine("Enter your Height (in centimeters): ");
height = int.Parse(Console.ReadLine());
if (height < 160)
Console.WriteLine("You are Dwarf person");
else if ((height >= 160) && (height <= 170))
Console.WriteLine("You are average height person");
else if (height >= 170)
Console.WriteLine("You are tall person");
else
Console.WriteLine("Entered height is abnormal");
}
}
Output:
Enter your Height (in centimeters):
172
You are tall person
Press any key to continue . . .
Explanation:
In the above program, we created a program class that contains Main() method, In the Main() method we created a local variable height initialized with 0. Then we took height as an input, and then check conditions and print the appropriate message on the console screen.
C# Basic Programs »