C Program To Calculate Surface Area of Cone

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

Formula To Calculate Surface Area of Cone

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

Note: sqrt() is a builtin method present in math.h header file.

surface area of cone

Related Read:
Basic Arithmetic Operations In C

Expected Output for the Input

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

Output:
Surface Area of Cone is 46.378838

Video Tutorial: C Program To Calculate Surface Area of Cone


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

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

Source Code: C Program To Calculate Surface Area of Cone

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

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

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

    s_area = PI * r * ( r + sqrt(h * h + r * r) );

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

    return 0;
}

Output 1:
Enter radius and height of the cone
8
18
Surface Area of Cone is 695.766663

Output 2:
Enter radius and height of the cone
5
14
Surface Area of Cone is 311.897278

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 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 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 Volume of Cylinder

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

Formula To Calculate Volume of Cylinder

volume = Base_Area x height;

Base of the Cylinder 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;

volume of Cylinder

where PI is 3.14159265359;

Related Read:
Basic Arithmetic Operations In C

Expected Output for the Input

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

Output:
Volume of Cylinder is 62.831856

Logic To Calculate Volume of Cylinder

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

volume = (PI x Radius2) x height;

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

PI value is 3.14159265359;

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

So volume of cylinder is 62.8 cubic meter.

Video Tutorial: C Program To Calculate Volume of Cylinder


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

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

Source Code: C Program To Calculate Volume of Cylinder

#include<stdio.h>

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

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

    volume = PI * r * r * h;

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

    return 0;
}

Output 1:
Enter Radius and Height of the Cylinder
2
5
Volume of Cylinder is 62.831856

Output 2:
Enter Radius and Height of the Cylinder
2
3
Volume of Cylinder is 37.699112

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 Find Area of Right Angled Triangle

Lets write a C program to calculate area of a right angled Triangle, by asking the user to enter its width and height.

Related Read:
Find Area of a Triangle Using Its Sides: C Program
Find Area of a Triangle Using Its Base and Height: C Program

Formula To Find Area of Right Angled Triangle

Area = (width * Height) / 2.0;

OR

Area = (width * Height * 0.5);

Note: If we divide an expression or number by 2, it’ll return only the integer part and the decimal part will be discarded. So we are dividing the expression by 2.0 (which is of type double).

C program To Find Area of Right Angled Triangle


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

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


Source Code: C program To Find Area of Right Angled Triangle

#include < stdio.h >

int main()
{
    float h, w, area;

    printf("Enter height and width of a right angled triangle\n");
    scanf("%f%f", &h, &w);

    area = (h * w) / 2.0;

    printf("Area of a Right Angled Triangle is %f\n", area);

    return 0;
}

Output:
Enter height and width of a right angled triangle
10
5
Area of a Right Angled Triangle is 25.000000

Validate the Input and Find Area of Triangle: C Program

#include < stdio.h >

int main()
{
    float h, w, area;

    printf("Enter height and width of a right angled triangle\n");
    scanf("%f%f", &h, &w);

    if(w == 0 || h == 0)
    {
        printf("Invalid Input\n");
    }
    else
    {
        area = (h * w) / 2.0;
        printf("Area of a Right Angled Triangle is %f\n", area);
    }

    return 0;
}

Output 1:
Enter height and width of a right angled triangle
10
5
Area of a Right Angled Triangle is 25.000000

Output 2:
Enter height and width of a right angled triangle
0
5
Invalid Input

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