Monday, June 18, 2012

To print the area of geometrical figure using Switch statement


/* To print the area of geometrical figure using Switch statement */

#include<stdio.h>

#include<conio.h>

void main()

{

  int choice;

  float a,b,area;

  clrscr();

  printf("\nGiven choices are:\n");

  printf("\n1-Circle");

  printf("\n2-Square");

  printf("\n3-Triangle");

  printf("\n4-Rectangle");

  printf("\n\nEnter your choice: ");

  scanf("%d",&choice);

  switch(choice)

  {

    case 1:

      printf("\nEnter the radius of circle: ");

      scanf("%f",&a);

      area=3.142*a*a;

      printf("\nArea of Circle=%f",area);

      break;

   case 2:

      printf("\nEnter the side of square: ");

      scanf("%f",&a);

      area=a*a;

      printf("\nArea of Square=%f",area);

      break;

   case 3:

      printf("\nEnter the base and height of triangle: ");

      scanf("%f%f",&a,&b);

      area=a*b/2;

      printf("\nArea of Triangle=%f",area);

      break;

   case 4:

      printf("\nEnter the length and breadth of rectangle: ");

      scanf("%f%f",&a,&b);

      area=3.142*a*a;

      printf("\nArea of Circle=%f",area);

      break;

   default:

     printf("Given choice does not exist!!!\n");

     break;

  }

  getch();

}

 

OUTPUT

 

Given choices are:

 

1-Circle

2-Square

3-Triangle

4-Rectangle

 

Enter your choice: 3

 

Enter the base and height of triangle: 40 32

 

Area of Triangle=640.000000

 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.