C++ To Calculate Area Of Circle, Rectangle And Triangle Using Switch Case

Find Area of Circle, Rectangle And Triangle now you can easily get a solution. Just take n input and put the values in given formula and your answer is on the screen according to your input.

1. Area of Circle =====> 3.14rr (r=Radius)
2. Area of Rectangle ==> a*b
3. Area of Triangle ===> sqrt(s(s-a)(s-b)*(s-c));

C++ To Calculate Area Of Circle, Rectangle And Triangle Using Switch Case

``````#include<iostream>
#include<math.h>
using namespace std;
int main()
{
float a,b,c,s,r,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 Radius Of The Circle: ";
cin>>r;
area=3.14*r*r;
break;
}
case 2:
{
cout<<"\nEnter Length And Breadth Of Rectangle:";
cin>>a>>b;
area=a*b;
break;
}
case 3:
{
cout<<"\nEnter Three Sides Of The Triangle:";
cin>>a>>b>>c;
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
break;
}
default: cout<<"\n Invalid Choice Try Again...!!!";
break;
}
cout<<"Area = "<<area<<endl;
return 0;
}``````

Output Of Program

1.Area Of Circle
2.Area Of Rectangle
3.Area Of Triangle

Enter Your Choice :2

Enter Length And Breadth Of Rectangle:8
7
Area = 56

Categories C++