Friday, 27 April 2012

Program in C for computing the Area of different Geometrical Figures


#include<stdio.h>
#include<conio.h>

int main()
{
 int figure;
 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 Code of the Figure:\n");
 scanf("%d",&figure);

    switch(figure)
 {
  case 1:
  printf("Enter the radius:\n");
  scanf("%f",&radius);
  area=3.1416*radius*radius;
  printf("\nArea of the Circle = %f\n",area);
  break;

  case 2:
  printf("Enter the length and breadth:\n");
  scanf("%f",&length,&breadth);
  area=length*breadth;
  printf("\nArea of the 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("\nArea of the Triangle = %f\n",area);
  break;

  case 4:
  printf("Enter the side of the square:\n");
  scanf("%f",&side);
  area=side*side;
  printf("\nArea of the Square = %f\n",area);
  break;

  default:
  printf("No such figure exists!\n");
  break;
 }
 getch();
 return 0;
}

No comments:

Post a Comment