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

Write a program which prompts the user to input a radius in centimeters and calc

ID: 3834170 • Letter: W

Question

Write a program which prompts the user to input a radius in centimeters and calculates and prints the area of a circle, volume of a sphere, and surface area of a sphere with that radius. Define pi as a defined constant (as a preprocessor command) with a value of 3.14159265. Use data type double for all variables. Using a complete sentence, output the circle area as a decimal with 3 digits following the decimal point. Using a complete sentence, output the volume of the sphere in exponential format with 4 digits following the decimal point when written in exponential notation. (Use the formula V = 4 pi r^3/3.0. Beware of truncating the fraction 4/3.) Again using a complete sentence, output the surface area of the sphere in g format with 4 significant digits. Test with a radius of 31.2 cm.

Explanation / Answer

#include <stdio.h>
#include <math.h>
#define PI 3.14159265

void main()
{
float radius, area,surface_area,volume;

printf("Enter the radius of a circle ");
scanf("%f", &radius);
area = PI * pow(radius, 2);
printf("Area of a circle = %.3f ", area);
surface_area = 4 * PI * radius * radius;
volume = (4.0/3) * PI * radius * radius * radius;
printf("Surface area of sphere is: %.4g", surface_area);
printf(" Volume of sphere is : %.4e", volume);
}

Sample output:

Enter the radius of the circle 31.2

Area of the circle = 3058.152

Surface area of sphere is: 1.223e+04

Volume of sphere is: 1.2722e+05

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote