In this tutorial you will learn about the C Program to find Area & Perimeter of Square and its application with practical example.
C Program to find Area & Perimeter of Square
In this tutorial, we will learn to create a C program that will find the Area & Perimeter of Square in C programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- While loop in C programming.
Program to find Area & Perimeter of Square:-
As we all know the c is a very powerful language. With the help of c programming language, we can make many programs. We can perform many input-output operations using c programming. In today’s tutorial, we take the input in the form size of a side of the square. Then we will find its area and parameter with the help of the c programming language.
With the help of this program, we can find the Area & Perimeter of the Square.
Algorithm:-
1 2 3 4 5 6 7 8 9 10 11 |
1. Declare the variables for the program. 2. Takeing the input side of the square from the user. 3. Passing that input number to calculate the perimeter. 4. Passing that input number to calculate the area. 5. Print the Result. 6. End the program. |
Program to find the Area & Perimeter of Square:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
/* * C Program to find area and perimeter of a square */ #include <stdio.h> int main() { /* Declaring the variable for the program for storing the data */ float side, perimeter,area; //side = to store the side of the square //perimeter = to store the side of the perimeter //area = to store the side of the area /* Taking the input side of the square from the user */ printf("Enter length of side of Square\n"); scanf("%f", &side); /* Calculating Perimeter of Square = 4 X Side */ perimeter = 4*side; printf("Perimeter of Square : %0.4f\n", perimeter); /* Calculating Area of Square = Side X Side */ area = side * side; printf("Area of square : %0.4f\n", area); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
![](https://www.w3adda.com/wp-content/uploads/2021/11/1-var-42.jpg)
- side = it will hold the float value.
- area = it will hold the float value.
- paremeter = it will hold the float value.
Taking the input from the message.
![](https://www.w3adda.com/wp-content/uploads/2021/11/4-area.jpg)