4. Create a fourth program called circles.c. In this program define a structure
ID: 3878428 • Letter: 4
Question
4. Create a fourth program called circles.c. In this program define a structure called circle A circle is defined by its coordinates (integers x, y) and its radius (float r). Your program will contain functions that give more information about circles. Feel free to google the formulas you man need for your functions. You can use 3.14 as an approximation of Pl Your program will contain the following functions a. void print circle(circle c): This function will print out the information stored in the circle structure in some human-readable manner float diameter(circle c): This function will return the diameter of circle c. float circumference(circle c): This function will return the circumference of circle c float area(circle c): This function will return the area of circle c. b. c. d.Explanation / Answer
If you have any problem with the answer just let me know in the comments and I'll try to solve it as soon as possible.
#include <stdio.h>
#include <math.h> // for value of Pi
/* Function declaration */
float Diameter(float radius);
float Circumference(float radius);
float Area(float radius);
int main()
{
float radius, dia, circ, area;
/* Input radius of circle from user */
printf("Enter radius of circle: ");
scanf("%f", &radius);
dia = Diameter(radius); // Call Diameter function
circ = Circumference(radius); // Call Circumference function
area = Area(radius); // Call Area function
printf("Diameter of the circle = %.2f units ", dia);
printf("Circumference of the circle = %.2f units ", circ);
printf("Area of the circle = %.2f sq. units", area);
return 0;
}
float Diameter(float radius)
{
return (2 * radius);
}
float Circumference(float radius)
{
return (2 * M_PI * radius); // M_PI = PI = 3.14 ...
}
float Area(float radius)
{
return (M_PI * radius * radius); // M_PI = PI = 3.14.
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.