Breralse 02: (making deolsion+looping fumotionB) Develop a Cfunction that aooept
ID: 3809087 • Letter: B
Question
Breralse 02: (making deolsion+looping fumotionB) Develop a Cfunction that aooepte a radius (floating-point value) of a circle. The function should calculate and return the area of the given circle Developac function that acoepts two sides Gboth floating-point values of a rectangle. The function should calculate and return the area of the given rectangle. Develop a C function that aooepts three sides (all floating-point values) of a triangle. The function should calculate and return the area of the given triangle. (Hinti apply Héron equation). After all, write a C program that reads repeatedly an option (option value can be i, 2, 3 or 4). The action prompted by the chosen option as follows: Option 1: Read a radius of a circle, call the circle function and print the area on the screen; Option 2: Read two sides of a rectangle, call the rectangle function and print the area on the screen; Option 3: Read three sides of a triangle, call the triangle function and print the area on the screen; Option 4: Exit from the program (printing Program ends while exit All the area should be displayed with 2decimal point format Ci.e. 12.34 -hint: apply 2) Output example: Read an option 1 Enter the radius: 245 Area is: 1886 Read an option: 2 Enter two sides: 1.638.4 Area is 391 Read an option: 3 Enter three sides 3.24.15.5 Area is 661 Read an option: Program ends.Explanation / Answer
#include<stdio.h>
#include<math.h>
float area(float rad);
float area(float len,float breadth);
float area(float side1,float side2,float side3);
int main()
{
float rad=0,len,breadth,sides=0,side1=0,side2=0,side3=0,tri=0;
int option;
printf(" Area of a Circle");
printf(" Area of a Rectangle");
printf(" Area of a Triangle");
printf(" Exit");
printf(" Read Option");
scanf("%d",&option);
switch(option)
{
case 1:
printf(" Enter Radius:");
scanf("%f",&rad);
printf(" Area is: %.2f",area(rad));
return(0);
case 2:
printf(" Enter Length:");
scanf("%f",&len);
printf(" Enter Breadth:");
scanf("%f",&breadth);
printf(" Area is: %.2f",area(len,breadth));
return(0);
case 3:
printf(" Enter Side1:");
scanf("%f",&side1);
printf(" Enter Side2:");
scanf("%f",&side2);
printf(" Enter Side3:");
scanf("%f",&side3);
tri=area(side1,side2,side3);
printf(" Area is: %.2f",area(tri));
return(0);
case 4:
printf(" Program Ends...");
return (0);
}
}
float area(float rad)
{
float areaofcircle;
areaofcircle = ((22/7) * rad * rad);
return(areaofcircle);
//return ( * rad * rad);
}
float area(float len,float breadth)
{
return (len * breadth);
}
float area(float side1,float side2, float side3)
{
float ans=0,sq=0,sides=0,peri=0;
peri=(side1+side2+side3);
sides = peri/2.0;
ans = (sides*(sides-side1)*(sides-side2)*(sides-side3));
sq = sqrt(ans);
return (sq);
}