In: Computer Science
C language <stdio.h> use double and const
Write a program that asks the user for the radius of a circle (as a double) and displays the diameter, circumference, and area of the circle.
Use a constant of 3.14159 as the value of pi. Have a blank line between the input and the output. Follow the 3 steps in the Information Processing Cycle - Input, Processing, and Output. The formulas needed are:
diameter = 2 * radius
circumference = 2 * pi * radius
area = pi * radius * radius
Have a blank line at the end of your program to separate the last line of output from your program from the "Press any key to continue . . .", and do this for all programs that you write.
Example Run #1:
(bold type is what is entered by the user)
Enter the radius of the circle (in inches): 5
The diameter of a circle with a radius of 5.00 inches is xx.xx
inches.
The circumference of a circle with a radius of 5.00 inches is xx.xx
inches.
The area of a circle with a radius of 5.00 inches is xx.xx square
inches.
The example run shows EXACTLY how your program input and output will look.
Your code is ...
#include<stdio.h>
int main()
{
double const pi = 3.14159;
double diameter, circumference, area, radius;
printf("Enter the radius of the circle (in
inches):");
scanf("%lf",&radius);
diameter = 2 * radius;
circumference = 2 * pi * radius;
area = pi * radius * radius;
printf("The diameter of a circle with a radius of
%.2lf inches is %.2lf inches\n", radius, diameter);
printf("The circumference of a circle with a radius of
%.2lf inches is %.2lf inches\n", radius, circumference);
printf("The area of a circle with a radius of %.2lf
inches is %.2lf inches", radius, area);
printf("\n");
return 0;
}