C Program - find the area of square, rectangle and triangle write in menu driven program - IProgramX

Q. Write a program having a menu with the following options and corresponding actions



Program

#include <stdio.h>
void main ()
{
      int choice,r,l,w,b,h;
      float area;
      printf("1. for area of square\n");
      printf("2. for area of rectangle\n");
      printf("3. for area of triangle\n");
      printf("Input your choice : ");
      scanf("%d",&choice);
      switch(choice)
      {
           case 1:
                 printf("enter length  of side of the square : ");
                 scanf("%d",&r);
                 area=r*r;
                 break;
            case 2:
                  printf("enter length and width of the rectangle : ");
                  scanf("%d%d",&l,&w);
                  area=l*w;
                  break;
            case 3:
                  printf("enter the base and height of the triangle :");
                  scanf("%d%d",&b,&h);
                  area=0.5*b*h;
                  break;
          }
          printf("The area is : %f\n",area);
}

Output:

1. for area of square
2. for area of rectangle
3. for area of triangle
Input your choice :3
enter the base and height of the triangle :5 7
The area is : 17.500000

Post a Comment

0 Comments