google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a program to calculate the areas of different geometrical figures - 2nd puc computer science

Write a program to calculate the areas of different geometrical figures

Write a program to calculate the areas of different geometrical figures.

#include<stdio.h>

#include<conio.h>

void main()

{

int figure;

float radius, area, length, breadth, base, height, side;

clrscr();

printf("-------------------------\n");

printf("1 Rectangle\n2 Triangle\n3 Circle\n4 Square\n");

printf("-------------------------\n");

printf("Choose the figure code from Menu: ");

scanf("%d",&figure);

switch(figure)

{

case 1: printf("Enter the length and breadth:\n");

         scanf("%f%f",&length,&breadth);

         area=length*breadth;

         printf("Area of a rectangle=%f",area);

         break;

case 2: printf("Enter the base and height of the triangle:\n");

         scanf("%f%f",&base,&height);

         area=0.5*base*height;

         printf("Area of a triangle=%f",area);

         break;

case 3: printf("Enter the radius of the circle: ");

         scanf("%f",&radius);

         area=3.142*radius*radius;

         printf("Area of a circle=%f",area);

         break;

case 4: printf("Enter the side of a square: ");

         scanf("%f",&side);

         area=side*side;

         printf("Area of a square=%f",area);

         break;

default: printf("Error in figure code");

}

getch();

}

Output:

 

run 1:

-------------------------

1 Rectangle

2 Triangle

3 Circle

4 Square

-------------------------

Choose the figure code from Menu: 1

Enter the length and breadth

2

3

Area of a rectangle=6.000000

 

run 2:

-------------------------

1 Rectangle

2 Triangle

3 Circle

4 Square

-------------------------

Choose the figure code from Menu: 2

Enter the base and height of the triangle

5

6

Area of a triangle=15.000000

 

run 3:

-------------------------

1 Rectangle

2 Triangle

3 Circle

4 Square

-------------------------

Choose the figure code from Menu: 3

Enter the radius of the circle: 8

Area of a circle=201.087997

 

run 4:

-------------------------

1 Rectangle

2 Triangle

3 Circle

4 Square

-------------------------

Choose the figure code from Menu: 4

Enter the side of a square: 3

Area of a square=9.000000


run 5:

-------------------------

1 Rectangle

2 Triangle

3 Circle

4 Square

-------------------------

Choose the figure code from Menu: 5

Error in figure code

Write a program to calculate the areas of different geometrical figures Write a program to calculate the areas of different geometrical figures Reviewed by Vision Academy on December 08, 2021 Rating: 5

No comments:

CheckOut

Powered by Blogger.