Ask Question
10 April, 06:41

Write a program to calculate surface area and volume of a sphere (ball). The program will ask user to input radius (meter (s)) of a sphere and return its area and volume (output should round to three decimal places). Use macro #define for value of π (suppose π = 3.1415927). Learn to use pow function for evaluating square and cubic in math. h of C programming library (Google ""pow c programming""). You can use scanf function and double type for radius input. Name your program file Hw2 Q1 Code. c.

Answers (1)
  1. 10 April, 06:51
    0
    The following program is to calculate the surface area and volume of a sphere (ball) using macro in c language.

    #include / /header file for math functions

    #define pi 3.1415 / /using macro

    #include / /header file for printf () or scanf ()

    int main () / /main function

    {

    double radius; / /radius is a double type variable

    float surface_area, vol; / /surface_area andvolume is a float type variable

    printf ("Enter the radius of the sphere : / n"); / /printf () is use to print an output

    scanf ("%lf", &radius); / /scanf () is use to take input from the user

    surface_area = 4 * pi * pow (radius, 2);

    vol = (4.0/3) * pi * pow (radius, 3);

    printf ("The Surface area of the sphere is: %.3f", surface_area); / / display surface area

    printf ("/n Volume of the sphere is : %.3f", vol); / / display volume

    return 0;

    }

    Output:

    Enter radius of the sphere : 4.4

    Surface area of sphere is: 243.278

    Volume of sphere is : 356.807

    Explanation:

    Here in this program we include the header file math. h and include the macro pi. after that taking the user input in radius and calculating the surface area and volume of sphere and finally display the result.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program to calculate surface area and volume of a sphere (ball). The program will ask user to input radius (meter (s)) of a sphere ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers
Sign In
Ask Question