In this post, we will learn how to find the surface area of a cube using C Programming language.
The Surface area of a cube = 6a2, where a is the length of the side of each edge of the cube.
- Surface Area = 6 x Side x Side
We will be using this formula in our program to find the surface area of a cube.
So, without further ado, let’s begin this tutorial.
C Program to Find Surface Area of Cube
// C Program to Find Surface Area of a Cube #include <stdio.h> int main(){ int side; float area; // Asking for input printf("Enter the side of the cube: "); scanf("%d", &side); // Calculating surface area area = 6 * side * side; // Output printf("Surface Area of Cube: %.2f", area); return 0; }
Output
Enter the side of the cube: 2
Surface Area of Cube: 24.00
How Does This Program Work ?
int side; float area;
In this program, we have declared one int data type variable and one float data type variable.
// Asking for input printf("Enter the side of the cube: "); scanf("%d", &side);
Then, the user is asked to enter the side of the cube.
// Calculating surface area area = 6 * side * side;
We calculate the surface area using the formula 6a2.
// Output printf("Surface Area of Cube: %.2f", area);
Finally, the result is printed on the screen using printf() function.
Conclusion
I hope after going through this post, you understand how to find the surface area of a cube using C Programming language.
If you have any doubt regarding the program, feel free to contact us in the comment section. We will be delighted to help you.
Also Read: