C Program To Find Area of Square
In this article, we are going to write a c program to find area of Square.
We will make this program in the following way -:
- C Program To Find Area of Square (Simple Way)
- C Program To Find Area of Square Using Function
- C Program To Find Area of Square Using Pointer
- C Program To Find Area of Square Using #define or Macro
To make this program, we will use the following concept given below.
If you do not know about these topics well, then you may not understand this program, so you should know about them in detail from the link given above.
Now without wasting time let’s start programming.
C Program To Find Area of Square (Simple Way)
Algorithm
- Program Start
- Declare Variables
- Input side from the User
- Calculating Area of square
- Display Result
- Program End
Program
#include<stdio.h>
void main()
{
int side, aos;
printf("\nEnter the Length of Side : ");
scanf("%d", &side);
aos = side * side;
printf("Area of Square : %d", aos);
}
Output
Enter the Length of Side : 6
Area of Square : 36
C Program To Find Area of Square Using Function
Algorithm
- Program Start
- Declare Variables
- Input side from the User
- Calling Function to Find Area of square
- Calculating Area of square
- Display Result
- Program End
Program
#include<stdio.h>
void aos(int s)
{
int area;
area = s*s;
printf("Area of Square : %d", area);
}
void main()
{
int side;
printf("\nEnter the Length of Side : ");
scanf("%d", &side);
aos(side);
}
Output
Enter the Length of Side : 3
Area of Square : 9
C Program To Find Area of Square Using Pointer
Program
#include<stdio.h>
int aos(int *s)
{
int area;
area = (*s)*(*s);
return area;
}
void main()
{
int side;
printf("\nEnter the Length of Side : ");
scanf("%d", &side);
printf("Area of Square : %d",aos(&side));
}
Output
Enter the Length of Side : 9
Area of Square : 81
C Program To Find Area of Square Using #define Macro
Program
#include<stdio.h>
#define aos(side) (side*side)
void main()
{
int side, aos;
printf("\nEnter the Length of Side : ");
scanf("%d", &side);
printf("Area of Square : %d", aos(side));
}
Output
Enter the Length of Side : 12
Area of Square : 144
Read More
- Download C Language Notes Pdf
- C Language Tutorial For Beginners
- C Programming Examples With Output
- 250+ C Programs for Practice PDF Free Download
Conclusion
So friends, in this article, we have written a c program to find area of Square in this ways.
- C Program To Find Area of Square (Simple Way)
- C Program To Find Area of Square Function
- C Program To Find Area of Square Using Pointer
- C Program To Find Area of Square Using #define or Macro
If you have difficulty to understand any program or have any doubts or questions, then tell me in the comment below.