## Logic to Calculate Area of Circle Rectangle and Triangle

Below are the formula to find the Area of Circle, Rectangle and Triangle. So first we are going to know the formulas and then after that we will implement in our program using switch case. So first we need to find the value of PI for area of radius, and for area of rectangle we need to length and width.

Now the most important is to find the area of Triangle with 3 sides, for this we will Use Heron's formula with all three sides a,b and c of Triangle and divide by 2 after that we will apply a formula. Below is the C++ Program to Calculate Area of Circle Rectangle and Triangle Using Switch Statement.

### Area of Circle Rectangle and Triangle Formulas

**Area of Circle:**3.14*r*r (r=Radius)

**Area of Rectangle:**a*b

**Area of Triangle:**sqrt(s*(s-a)*(s-b)*(s-c));

Where S=(a+b+c)/2;

## C++ Program to Calculate Area of Circle Rectangle and Triangle Using Switch Statement

```
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
/*Visit: https://www.programmingwithbasics.com/2015/11/write-c-to-calculate-area-of-circle.html*/
float a, b, c, s, radius, area;
int ch;
cout<<"1.Area Of Circle";
cout<<"\n2.Area Of Rectangle";
cout<<"\n3.Area Of Triangle \n";
cout<<"\nEnter Your Choice :";
cin>>ch;
switch(ch)
{
case 1:
{
cout<<"\nEnter the Radius of Circle: ";
cin>>radius;
area=3.14159*radius*radius;
cout<<"Area of Circle = "<<area<<endl;
break;
}
case 2:
{
cout<<"\nEnter the Length and Breadth of Rectangle:";
cin>>a>>b;
area=a*b;
cout<<"Area of Rectangle = "<<area<<endl;
break;
}
case 3:
{
cout<<"\nEnter All Three Sides of Triangle with 3 Sides:";
cin>>a>>b>>c;
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
cout<<"Area of Triangle = "<<area<<endl;
break;
}
default: cout<<"\n Invalid Choice Try Again...!!!";
break;
}
return 0;
}
```

### The Output of Area of Circle Rectangle and Triangle

### Check This Out

- C++ Program To Convert Celsius To Fahrenheit And Vice Versa Using Switch Case
- C++ Program for Arithmetic Operations Using Switch Case
- C++ Program to Calculate Grade of Student Using Switch Statement
- C Program to Convert Temperature from Fahrenheit to Celsius and Vice Versa
- C Program for Find a Grade of Given Marks Using Switch Case

## 0 Comments: