ADVERTISEMENT
ADVERTISEMENT

C program to calculate the volume of Cube

Here, we are going to learn how to calculate the volume of Cube using C program?
Submitted by Nidhi, on August 06, 2021

Problem Solution:

Read the length of the side of the Cube from the user, and calculate the volume of the Cube.

Volume of Cube formula: side3 or a3

Where, side (or a) is the length of the side (i.e., edge)

Program:

The source code to calculate the volume of Cube is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.

// C program to calculate the volume of Cube

#include <stdio.h>

float calcuateVolumeOfCube(float side)
{
    float result = 0.0F;

    result = side * side * side;

    return result;
}

int main()
{
    float side = 0;
    float volume = 0;

    printf("Enter the length of side: ");
    scanf("%f", &side);

    volume = calcuateVolumeOfCube(side);

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

    return 0;
}

Output:

RUN 1:
Enter the length of side: 2.4
Volume of Cube is: 13.824001

RUN 2:
Enter the length of side: 10.23
Volume of Cube is: 1070.598999

RUN 3:
Enter the length of side: 12.0
Volume of Cube is: 1728.000000

Explanation:

In the above program, we created two functions calcuateVolumeOfCube() and  main(). The calcuateVolumeOfCube() function is used to calculate the volume of Cube based on the given side of Cube.

In the main() function, we read the value of the side of Cube from the user. Then we called the calcuateVolumeOfCube() function to calculate the volume of the Cube. After that, we printed the result on the console screen.

C Basic Programs »


ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.