In this post, we will learn how to calculate the area of a square using C Programming language.
This program asks the user to enter the side of the square, then it will calculate the area of the square by multiplying the side by itself.
So, without further ado, let’s begin this tutorial.
C Program To Calculate Area of a Square
// C Program to Calculate Area of Square #include <stdio.h> int main(){ int side, area; // Asking for input printf("Enter the side of the square: "); scanf("%d", &side); // Calculating Square area = side * side; // Displaying output printf("Area of the Square having side %d is: %d", side, area); return 0; }
Output
Enter the side of the square: 7
Area of the Square having side 7 is: 49
How Does This Program Work ?
int side, area;
In this program, we have declared two int data type variables named side and area.
// Asking for input printf("Enter the side of the square: "); scanf("%d", &side);
Then, the user is asked to enter the side of the square.
// Calculating Square area = side * side;
Area of Square = Side * Side
// Displaying output printf("Area of the Square having side %d is: %d", side, area);
Finally, the area of the square is displayed to the screen using printf() function.
Conclusion
I hope after going through this post, you understand how to calculate the area of a square 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: