Find the diameter, circumference, and area of the circle using functions.
#include <stdio.h>
#include <math.h>
///Calculate diameter of circle whose num is given
double getDiameter(double num)
{
return (2 * num);
}
//Calculate circumference of circle whose num is given
double getCircumference(double num)
{
return (2 * M_PI * num); // M_PI = PI = 3.14 ...
}
//Find area of circle whose num is given
double getArea(double num)
{
return (M_PI * num * num); // M_PI = PI = 3.14 ...
}
int main()
{
float num, dia, circ, area;
/* Input num of circle from user */
printf("Enter num of circle: ");
scanf("%f", &num);
dia = getDiameter(num);
circ = getCircumference(num);
area = getArea(num);
printf("Diameter of the circle = %.2f units\n", dia);
printf("Circumference of the circle = %.2f units\n", circ);
printf("Area of the circle = %.2f sq. units", area);
return 0;
}
Output
Enter num of circle : 5
Diameter of the circle = 10.00 units
Circumference of the circle = 31.42 units
Area of the circle = 78.54 sq.units
0 Comments