Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program using C. Write a program circle.c that calculates the area and circumfer

ID: 3846525 • Letter: P

Question

Program using C.

Write a program circle.c that calculates the area and circumference of a circle. The program should include the following function. Do not modify the function prototype.

void area_circum(double radius, double *area, double *circum);

The function takes a parameter of double type for the radius of the circle. The area parameter points to a variable in which the function will store the area of the circle. The circum parameter points to a variable in which the function will store the circumference of the circle. The main function should ask the user to enter the radius of the circle and call the area_circum function to calculate the area and circumference. The main function should contain the printf statements that display the result with three decimal digits.

Explanation / Answer

#include <stdio.h>
void area_circum(double radius, double *area, double *circum);
int main()
{
double radius, area, circum;
printf("Enter the circle radius: ");
scanf("%lf", &radius );
area_circum(radius, &area, &circum);
printf("Circle area is %.3lf ", area);
printf("Circle circumference is %.3lf ", circum);
return 0;
}

void area_circum(double radius, double *area, double *circum) {
*area = 3.14 * radius * radius;
*circum = 2 * 3.14 * radius;
  
}

Output:

sh-4.2$ gcc -o main *.c                                                                                                                                                                              

sh-4.2$ main                                                                                                                                                                                         

Enter the circle radius: 2.5                                                                                                                                                                         

Circle area is 19.625                                                                                                                                                                                

Circle circumference is 15.700