C Program To Find Area of Rectangle
In this article, we are going to write a c program to find area of rectangle.
We will make this program in the following way -:
- C Program To Find Area of Rectangle (Simple Way)
- C Program To Find Area of Rectangle Using Function
- C Program To Find Area of Rectangle Using Pointer
- C Program To Find Area of Rectangle Using 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 Rectangle (Simple Way)
Algorithm
- Program Start
- Declare Variables
- Input length and breadth From User
- Calculate Area of Rectangle
- Display Result
- Program End
Program
//C Program To Find Area of Rectangle
#include<stdio.h>
void main()
{
float l,b,area;
printf("Enter length of rectangle: ");
scanf("%f",&l);
printf("Enter breadth of rectangle: ");
scanf("%f",&b);
area=(l*b);
printf("Area of Rectangle : %f\n",area);
}
Output
Enter length of rectangle: 10
Enter breadth of rectangle: 12
Area of Rectangle : 120.000000
C Program To Find Area of Rectangle Using Function
Algorithm
- Program Start
- Declare Variables
- Input length and breadth From User
- Calling Function To Calculate Area of Rectangle
- Calculating Area of rectengle
- Display Result
- Program End
Program
//C Program To Find Area of Rectangle Using Function
#include<stdio.h>
void aor(float l, float b);
void main()
{
float l,b;
printf("Enter length of rectangle: ");
scanf("%f",&l);
printf("Enter breadth of rectangle: ");
scanf("%f",&b);
aor(l,b);
}
void aor(float l, float b)
{
float area;
area = (l*b);
printf("Area of Rectangle : %f\n",area);
}
Output
Enter length of rectangle: 3
Enter breadth of rectangle: 5
Area of Rectangle : 15.000000
C Program To Find Area of Rectangle Using Pointer
Program
//C Program To Find Area of Rectangle Using Pointer
#include<stdio.h>
void aor(float *l, float *b);
void main()
{
float l,b;
printf("Enter length of rectangle: ");
scanf("%f",&l);
printf("Enter breadth of rectangle: ");
scanf("%f",&b);
aor(&l,&b);
}
void aor(float *l, float *b)
{
float area;
//here l and b is a pointer variable
area = (*l)*(*b);
printf("Area of Rectangle : %f\n",area);
}
Output
Enter length of rectangle: 30
Enter breadth of rectangle: 15
Area of Rectangle : 45.000000
C Program To Find Area of Rectangle Using Micro or #Define
Program
//C Program To Find Area of Rectangle Using #define
#include<stdio.h>
#define area(l,b) (l*b)
void main()
{
float l,b,area;
printf("Enter length of rectangle: ");
scanf("%f",&l);
printf("Enter breadth of rectangle: ");
scanf("%f",&b);
printf("Area of Rectangle : %f\n",area(l,b));
}
Output
Enter length of rectangle: 30
Enter breadth of rectangle: 50
Area of Rectangle : 150.000000
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 Rectangle in this ways -:
- C Program To Find Area of Rectangle (Simple Way)
- C Program To Find Area of Rectangle Using Function
- C Program To Find Area of Rectangle Using Pointer
- C Program To Find Area of Rectangle Using Macro
If you have difficulty to understand any program or have any doubts or questions, then tell me in the comment below.