C program to accept a figure code and find the ares of different geometrical figures such as circle, square, rectangle etc using switch

by Nideesh C on April 13, 2011 · 1 comment

in C Programming




/* C program to accept a figure code and find the ares of different geometrical figures such as circle, square, rectangle etc using switch   */

#include <stdio.h>

void main()
{
int    fig_code;
float  side,base,length,breadth,height,area,radius;

printf(“————————-\n”);
printf(” 1 –> Circle\n”);
printf(” 2 –> Rectangle\n”);
printf(” 3 –> Triangle\n”);
printf(” 4 –> Square\n”);
printf(“————————-\n”);

printf(“Enter the Figure code\n”);
scanf(“%d”,&fig_code);

switch(fig_code)
{
case 1:  printf(“Enter the radius\n”);
scanf(“%f”,&radius);
area=3.142*radius*radius;
printf(“Area of a circle=%f\n”, area);
break;

case 2:  printf(“Enter the breadth and length\n”);
scanf(“%f %f”,&breadth, &length);
area=bredth *length;
printf(“Area of a Rectangle=%f\n”, area);
break;

case 3:  printf(“Enter the base and height\n”);
scanf(“%f %f”,&base,&height);
area=0.5 *base*height;
printf(“Area of a Triangle=%f\n”, area);
break;

case 4:  printf(“Enter the side\n”);
scanf(“%f”,&side);
area=side * side;
printf(“Area of a Square=%f\n”, area);
break;

default: printf(“Error in figure code\n”);
break;

}   /* End of switch */

}   /* End of main() */
/*—————————————————-
Output
Run 1
————————-
1 –> Circle
2 –> Rectangle
3 –> Triangle
4 –> Square
————————-
Enter the Figure code
2
Enter the breadth and length
2
6
Area of a Rectangle=12.000000

Run 2
————————-
1 –> Circle
2 –> Rectangle
3 –> Triangle
4 –> Square
————————-
Enter the Figure code
3
Enter the base and height
5
7
Area of a Triangle=17.500000

——————————————————*/

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to find the area of a circle, given the radius
  2. C program to find the area of a triangle, given three sides
  3. C program to compute the surface area and volume of a cube
  4. C program to accept two matrices and find the sum and difference of the matrices
  5. C Program to accept two matrices and check if they are equal

Leave a Comment

{ 1 trackback }

Previous post:

Next post: