A Learning Platform

SUCCESS

Success = Discipline + Consistency + Sacrifice.
Discipline - in what you do.
Consistency - in what you do.
Sacrifice - for what you do.

                   -- Manjunatha C. P. --

Area & Volume of Sphere C Program

C Program to find the Area & Volume of Sphere when radius is given.

A sphere is a solid figure bounded by a curved surface such that every point on the surface is the same distance from the centre. 

Formula:

Surface Area of Sphere = 4πr², where r is the radius.
Volume of sphere = 4/3 πr3 , where r is the radius.

Output: Area and Volume Of Sphere
Input: Radius of sphere

Description:

r – Radius of sphere.
a – Area of sphere.
v – Volume of sphere.
π – Pi : 3.14 (22/7)

Algorithm to find the surface area and volume of sphere.

STEP 1: START
STEP 2: READ the value of radius.
              READ r
STEP 3: CALCULATE the values of area and volume
              Area = 4 * 3.14 * r2
              Volume = 4/3 * 3.14 * r3
 STEP 4: PRINT the values of area and volume
              PRINT a , v
STEP 5: END

C Program to find the surface area and volume of sphere.

#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
 
    float r;
    float a, v;
    printf("Enter radius of the sphere : \n");
    scanf("%f", &r);
    a =  4 * 3.14 * r * r;
    v = (4.0/3.0) * 3.14 * r * r * r;
    printf("Surface area of sphere is: %f", a);
    printf("\n Volume of sphere is : %f", v);
    getch();
}

Output 1:

Enter radius of the sphere :
10
Surface area of sphere is: 1256.000000
Volume of sphere is : 4186.666504

Output 2:

Enter radius of the sphere :
5
Surface area of sphere is: 314.000000
Volume of sphere is : 523.333313

NOTE:

v = (4.0/3.0) * 3.14 * r * r * r;
In the above expression built in type conversion is used. Do not use 4/3 in the expression. Use instead 4.0/3.0.
Remember division of 2 integers always leads to an integer output. Division of integer and float leads to an floating point output.