Pages

Showing posts with label choice. Show all posts
Showing posts with label choice. Show all posts

Sunday, February 15, 2015

C program to calculate area of a circle a rectangle or a triangle depending upon users choice




#include<iostream.h>
#include<conio.h>
#include<math.h>


void main()
{
clrscr(); //to clear the screen
float a,b,c,s,r,area;
int ch;
cout<<"***Menu***
1.Area of circle
2.Area of Rectangle";

cout<<"
3.Area of triangle
Enter your choice:";

cin>>ch;

switch(ch)
{
case 1:
{
cout<<"
Enter radius of the circle:";

cin>>r;
area=3.14*r*r;
break;
}
case 2:
{
cout<<"
Enter length and breadth:";

cin>>a>>b;
area=a*b;
break;
}
case 3:
{
cout<<"
Enter 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<<"
Wrong choice...!!!";

break;
}


cout<<"Area="<<area;
getch(); //to stop the screen
}
Read more »

Thursday, February 12, 2015

C Program to do arithmetic operations according to user choice using switch case

include<iostream.h>
#include<conio.h>

void main()
{       clrscr();
int a,b;
char c;
cout<<"Enter any expression(ex:3*7):";
cin>>a>>c>>b;

switch(c)
{
case+: cout<<"
Result:"<<a+b;

break;

case-: cout<<"
Result:"<<a-b;

break;

case*: cout<<"
Result:"<<a*b;

break;

case/: cout<<"
Result:"<<a/b;

break;

case%:  cout<<"
Result:"<<a%b;

break;
}

getch();
}
Read more »