Input
1. choose 1(rectangle) or 2(circle) or 3(triangle)
Output:
1.Any one
Method:
1.start
2.write " 1. Rectangle 2. Circle and 3. Triangle";
3. read choice
4. write choice
5,. //logic
switch(choice)
{
case 1:
{
//logic for area of rectangle
write" enter the length and breadth ";
read l and b
A=l*b;
write" Area of rectangle",A;
break;
}
case 2:
{
//logic for Area of circle
Write " enter the radius";
read r
A= 3.14*r*r
write " Area of circle",A
break;
}
case 3:
{
//logic for Area of triangle
write "enter the base and height";
read b and h
A=0.5 * b * h;
write " Area of triangle",A;
}
default:
{
write " wrong choice ";
break;
}
}// switch end
6.stop
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
int choice;
float l,b,A,r,h;
cout<<"Enter the Choice: 1. Rectangle 2.Circlecle ane 3.Triangle \n";
cin>>choice;
cout<<"choice="<<choice<<endl;
//logic
switch(choice)
{ case 1: {
//logic for area of rectangle
cout<<" Enter the length and breadath \n";
cin>>l>>b;
A=l*b;
cout<<"\nArea of rectangle="<<A<<endl;
break;
}
case 2: {
//logic for Area of circle
cout<<"\nEnter the radius\n";
cin>>r;
A=3.14*r*r;
cout<<"Area of Circle="<<A<<endl;
break;
}
case 3: {
//logic for Area of triangle
cout<<"\n Enter the base and height \n";
cin>>b>>h;
A=0.5*b*h;
cout<<"\nArea of triangle ="<<A<<endl;
break;
}
default:
{
cout<<"\n wrong choice \n";
break;
}
}//switch end
}
1. choose 1(rectangle) or 2(circle) or 3(triangle)
Output:
1.Any one
Method:
1.start
2.write " 1. Rectangle 2. Circle and 3. Triangle";
3. read choice
4. write choice
5,. //logic
switch(choice)
{
case 1:
{
//logic for area of rectangle
write" enter the length and breadth ";
read l and b
A=l*b;
write" Area of rectangle",A;
break;
}
case 2:
{
//logic for Area of circle
Write " enter the radius";
read r
A= 3.14*r*r
write " Area of circle",A
break;
}
case 3:
{
//logic for Area of triangle
write "enter the base and height";
read b and h
A=0.5 * b * h;
write " Area of triangle",A;
}
default:
{
write " wrong choice ";
break;
}
}// switch end
6.stop
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
int choice;
float l,b,A,r,h;
cout<<"Enter the Choice: 1. Rectangle 2.Circlecle ane 3.Triangle \n";
cin>>choice;
cout<<"choice="<<choice<<endl;
//logic
switch(choice)
{ case 1: {
//logic for area of rectangle
cout<<" Enter the length and breadath \n";
cin>>l>>b;
A=l*b;
cout<<"\nArea of rectangle="<<A<<endl;
break;
}
case 2: {
//logic for Area of circle
cout<<"\nEnter the radius\n";
cin>>r;
A=3.14*r*r;
cout<<"Area of Circle="<<A<<endl;
break;
}
case 3: {
//logic for Area of triangle
cout<<"\n Enter the base and height \n";
cin>>b>>h;
A=0.5*b*h;
cout<<"\nArea of triangle ="<<A<<endl;
break;
}
default:
{
cout<<"\n wrong choice \n";
break;
}
}//switch end
}
No comments:
Post a Comment