﻿ C# Sharp exercises: A menu-driven program to compute the area of the various geometrical shape - w3resource

# C# Sharp Exercises: A menu-driven program to compute the area of the various geometrical shape

## C# Sharp Conditional Statement: Exercise-24 with Solution

Write a program in C# Sharp which is a Menu-Driven Program to compute the area of the various geometrical shape.

Sample Solution:-

C# Sharp Code:

``````using System;
public class Exercise24
{
public static void Main()
{
int choice,r,l,w,b,h;
double area=0;

Console.Write("\n\n");
Console.Write("A menu driven program to compute the area of various geometrical shape:\n");
Console.Write("-------------------------------------------------------------------------");
Console.Write("\n\n");

Console.Write("Input 1 for area of circle\n");
Console.Write("Input 2 for area of rectangle\n");
Console.Write("Input 3 for area of triangle\n");

switch(choice)
{
case 1:
Console.Write("Input radius of the circle : ");
area=3.14*r*r;
break;
case 2:
Console.Write("Input length  of the rectangle : ");
Console.Write("Input  width of the rectangle : ");
area=l*w;
break;
case 3:
Console.Write("Input the base of the triangle :");
Console.Write("Input the hight of the triangle :");
area=.5*b*h;
break;
}
Console.Write("The area is : {0}\n",area);
}
}
```
```

Sample Output:

```A menu driven program to compute the area of various geometrical shape:
-------------------------------------------------------------------------
Input 1 for area of circle
Input 2 for area of rectangle
Input 3 for area of triangle
Input length  of the rectangle : 20
Input  width of the rectangle : 30
The area is : 600
```

Flowchart:

C# Sharp Code Editor: