Write a C program to input length and width of a rectangle and find area of the given rectangle.
Here, you can see that we will find Area of Perimeter. The amount of space inside a shape is called Area. The Formula for the Area of a rectangle is Area = Length * Breadth . The standard unit of area is square units which is generally represented as square inches, square feet, etc. The distance around the edge of a shape is called perimeter. The Formula for the Perimeter of a rectangle is Perimeter = 2(Length + Breadth).
Inside the program, first of all we find the area of the perimeter in the C program. After that, by finding the area of the perimeter, we can find out which of the two has a larger area.
Code:
// Find Area of Perimeter and
// check who's greater
#include <stdio.h>
int main()
{
float langth ,breadth;
printf("Enter length: ");
scanf("%f", &length);
printf("Enter breadth: ");
scanf("%f", &breadth);
// Calculate area
float area = langth * breadth;
// Calculate perimeter
float peri = 2 * (langth + breadth);
// Output the results
printf("Area of the Rectengle: %.2f\n",area);
printf("Perimeter of the Rectangle: %.2f\n",peri);
// Compare area and parimeter
if (area > peri)
{
printf("\n The area is greater than the perimeter.");
}
else if (peri > area)
{
printf("\n The perimeter is greater than the area.");
}
else
{
printf("\n The area and parimeter are equal.");
}
return 0;
}
Output:
Enter length: 14
Enter breadth: 12
Area of the Rectengle: 168.00
Perimeter of the Rectangle: 52.00
The area is greater than the perimeter.
