C program for area of a sphere

Write a c program to find the volume and surface area of sphere

C program for area of a sphere



C code:

#include<stdio.h>
#include<math.h>

int main(){

    float r;
    float surface_area,volume;

    printf("Enter radius of the sphere : ");
    scanf("%f",&r);

    surface_area =  4* M_PI * r * r;
    volume = (4.0/3) * M_PI * r * r * r;

    printf("Surface area of sphere is: %.3f",surface_area);
    printf("\nVolume of sphere is : %.3f",volume);

    return 0;
}

Sample output:

Enter radius of the sphere: 5
Surface area of sphere is: 314.159
Volume of sphere is: 523.599
 
Formula of surface area of sphere:
Surface_area = 4 * Pie * r2

Formula of volume of sphere:
Volume = 4/3 * Pie * r3
Pie = 22/7 or 3.1415926535...
 

No comments:

Post a Comment