C Program To Calculate Volume of Cone

Given the values for radius and height of a Cone, write a C program to calculate volume of the Cone.

Formula To Calculate Volume of Cone

volume = ( Base_Area x height ) / 3.0;

Base of the Cone is a Circle. Area of Circle is PI x Radius2

So lets replace Base_Area with Area of Circle: PI x Radius2.

Therefore, volume = ( (PI x Radius2) x height ) / 3.0;

volume of Cone

where PI is approximately equal to 3.14159265359;

Related Read:
Basic Arithmetic Operations In C

Expected Output for the Input

User Input:
Enter radius and height of the cone
2
5

Output:
Volume of Cone is 20.933334

Logic To Calculate Volume of Cone

We ask the user to enter values for radius and height of the Cone. If user enters 2m and 5m. Then we use the formula to calculate the Volume of Cone:

volume = (PI x Radius2 x height) / 3.0;

User input:
radius = 2m;
height = 5m;

PI value is 3.14159265359;

volume = ( PI x Radius2 x height ) / 3.0;
volume = ( 3.14 x (2m)2 x (5m) ) / 3.0;
volume = ( 3.14 x 4(m)2 x 5(m) ) / 3.0;
volume = ( 3.14 x 20 m3 ) / 3.0;
volume = ( ‭62.8 m3 ) / 3.0;
volume = 20.93‬ m3;

So volume of Cone is 20.93 cubic meter.

Video Tutorial: C Program To Calculate Volume of Cone


[youtube https://www.youtube.com/watch?v=yjyQadX03A8]

YouTube Link: https://www.youtube.com/watch?v=yjyQadX03A8 [Watch the Video In Full Screen.]

Source Code: C Program To Calculate Volume of Cone

#include<stdio.h>

int main()
{
    const float PI = 3.14;
          float r, h, volume;

    printf("Enter radius and height of the cone\n");
    scanf("%f%f", &r, &h);

    volume = (PI * r * r * h) / 3.0;

    printf("Volume of Cone is %f\n", volume);

    return 0;
}

Output 1:
Enter radius and height of the cone
8
18
Volume of Cone is 1205.760010

Output 2:
Enter radius and height of the cone
5
14
Volume of Cone is 366.333344

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

C Program To Calculate Surface Area of Sphere

Given the value for radius of a Sphere, write a C program to calculate Surface Area of the Sphere.

Formula To Calculate Surface Area of Sphere

When radius value is known: Area = 4 * π * radius²,
When diameter value is known: Area = π * diameter²,
When volume value is known: Area = ³√(36 * π * Volume²).

where π (PI) is approximately equal to 3.14

surface area of sphere

Related Read:
Basic Arithmetic Operations In C

Logic To Calculate Surface Area of Sphere

We ask the user to enter the value of radius of the sphere. We apply the formula:
Surface_ Area = 4 * PI * radius2
where π (PI) is approximately equal to 3.14

Expected Output for the Input

User Input:
Enter Radius of the Sphere
5

Output:
Surface Area of Sphere is 314.000000

Video Tutorial: C Program To Calculate Surface Area of Sphere


[youtube https://www.youtube.com/watch?v=2llOHesCV70]

YouTube Link: https://www.youtube.com/watch?v=2llOHesCV70 [Watch the Video In Full Screen.]

Source Code: C Program To Calculate Surface Area of Sphere

#include<stdio.h>

int main()
{
    const float PI = 3.14;
          float r, area;

    printf("Enter Radius of the Sphere\n");
    scanf("%f", &r);

    area = ( 4 * PI * r * r );

    printf("Surface Area of Sphere is %f\n", area);

    return 0;
}

Output 1:
Enter Radius of the Sphere
2
Surface Area of Sphere is 50.240002

Output 2:
Enter Radius of the Sphere
10
Surface Area of Sphere is 1256.000000

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

C Program To Calculate Volume of Sphere

Given the value for radius of a Sphere, write a C program to calculate volume of the Sphere.

Formula To Calculate Volume of Sphere

volume = ( 4 * PI * radius3 ) / 3.0;

OR

volume = ( 1.333 * PI * radius3 );

volume of sphere

where PI is approximately equal to 3.14;

Related Read:
Basic Arithmetic Operations In C

Expected Output for the Input

User Input:
Enter Radius of the Sphere
5

Output:
Volume of Sphere is 523.333374

Logic To Calculate Volume of Sphere

We ask the user to enter value for radius of the Sphere. If user enters 5 inche. Then we use the formula to calculate the Volume of Sphere:

volume = ( 4 * PI * radius3 ) / 3.0;

User input:
radius = 5 inches;

PI value is approximately equal to 3.14;

volume = ( 4 * PI * radius3 ) / 3.0
volume = ( 4 * 3.24 * (5 inches)3) / 3.0
volume = ( ‭12.56‬ * 125 inches3 ) / 3.0
volume = ( ‭12.56‬ * 125 inches3 ) / 3.0
volume = ‭1,570‬ inches3 / 3.0
volume = ‭523.33 inches3

Video Tutorial: C Program To Calculate Volume of Sphere


[youtube https://www.youtube.com/watch?v=rpQzrFSWj6c]

YouTube Link: https://www.youtube.com/watch?v=rpQzrFSWj6c [Watch the Video In Full Screen.]

Source Code: C Program To Calculate Volume of Sphere

#include<stdio.h>

int main()
{
    const float PI = 3.14;
          float r, volume;

    printf("Enter Radius of the Sphere\n");
    scanf("%f", &r);

    volume = ( 4 * PI * r * r * r ) / 3.0;

    printf("Volume of Sphere is %f\n", volume);

    return 0;
}

Output 1:
Enter Radius of the Sphere
3
Volume of Sphere is 113.040001

Output 2:
Enter Radius of the Sphere
14
Volume of Sphere is 11488.213867

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

C Program To Calculate Surface Area of Cylinder

Given the values for radius and height of a Cylinder, write a C program to calculate Surface Area of the Cylinder.

Formula To Calculate Surface Area of Cylinder

Surface_Area = (2 * PI * radius * height) + (2 * PI * radius * radius);
where PI is approximately equal to 3.14

surface area of Cylinder

Related Read:
Basic Arithmetic Operations In C
Area of Rectangle: C Program
Calculate Area of a Circle without using math.h library: C
C Program To Calculate Circumference of Circle

Logic of Surface Area of Cylinder Formula


A solid Cylinder has 2 circles. One at the top and one at the bottom. Area of a Circle is PI * radius2. Since there are 2 Circles in the Cylinder, we multiply it by 2.

i.e., 2 (PI * radius2)

Next lets cut the cylinder at one end and open it. It forms a rectangle. Now height of the rectangle and height of the Cylinder are same. Width of the rectangle is equal to circumference of the circle, since top and bottom of the Cylinder are circles.

So, area of rectangle = (2 * PI * radius) * height

Therefore, Surface Area of Cylinder is:

SA = ( (2 * PI * radius) * height ) + ( 2 (PI * radius2) );

Expected Output for the Input

User Input:
Enter Radius and Height of the Cylinder
2
5

Output:
Surface Area of Cylinder is 87.920006

Video Tutorial: C Program To Calculate Surface Area of Cylinder


[youtube https://www.youtube.com/watch?v=9GGagAMiMSc]

YouTube Link: https://www.youtube.com/watch?v=9GGagAMiMSc [Watch the Video In Full Screen.]

Source Code: C Program To Calculate Surface Area of Cylinder

#include<stdio.h>

int main()
{
    const float PI = 3.14;
          float r, h, Area;

    printf("Enter Radius and Height of the Cylinder\n");
    scanf("%f%f", &r, &h);

    Area = (2 * PI * r * h) + (2 * PI * r * r);

    printf("Surface Area of Cylinder is %f\n", Area);

    return 0;
}

Output 1:
Enter Radius and Height of the Cylinder
5
10
Surface Area of Cylinder is 471.000031

Output 2:
Enter Radius and Height of the Cylinder
2
13
Surface Area of Cylinder is 188.400009

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

C Program To Calculate Circumference of Circle

Given the radius of a Circle, write a C program to calculate circumference of the Circle.

Formula To Calculate Circumference of Circle

circumference = 2 * PI * radius;
Where PI is approximately equal to 3.14

Related Read:
Basic Arithmetic Operations In C

Expected Output for the Input

User Input:
Enter Radius of the Circle
5

Output:
Circumference of the Circle is 31.400002

Video Tutorial: C Program To Calculate Circumference of Circle


[youtube https://www.youtube.com/watch?v=o2r2bDOuCX4]

YouTube Link: https://www.youtube.com/watch?v=o2r2bDOuCX4 [Watch the Video In Full Screen.]

Source Code: C Program To Calculate Circumference of Circle

#include<stdio.h>

int main()
{
    const float PI = 3.14;
          float r, c;

    printf("Enter Radius of the Circle\n");
    scanf("%f", &r);

    c = 2 * PI * r;

    printf("Circumference of the Circle is %f\n", c);

    return 0;
}

Output 1:
Enter Radius of the Circle
10
Circumference of the Circle is 62.800003

Output 2:
Enter Radius of the Circle
41
Circumference of the Circle is 257.480011

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert