ADVERTISEMENT
ADVERTISEMENT

C program to calculate the area of Cube

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

Problem Solution:

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

Area of Cube formula: 6 x side2 or 6a2

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

Program:

The source code to calculate the area 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 area of Cube

#include <stdio.h>

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

    result = 6.0 * side * side;

    return result;
}

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

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

    area = calcuateAreaOfCube(side);

    printf("Area of Cube is: %f\n", area);

    return 0;
}

Output:

RUN 1:
Enter the length of side: 2.4
Area of Cube is: 34.560001

RUN 2:
Enter the length of side: 10.23
Area of Cube is: 627.917358

RUN 3:
Enter the length of side: 12.0
Area of Cube is: 864.000000

Explanation:

In the above program, we created two functions calcuateAreaOfCube() and main(). The calcuateAreaOfCube() function is used to calculate the area 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 calcuateAreaOfCube() function to calculate the area of the Cube.

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.