Find the area and perimeter of square and rectangle. Inputs the side(s) through the keyboard.

In order to find the solution of this program, you must know their formulas. Below you can find their formulas.

## Formula 🧠

**Area of Square** = s^{2} and **Perimeter of Square** = 4(s), where s = side. **Area of Rectangle** = l * w and **Perimeter of Rectangle** = 2(l + w)

## Tutorial 📺

## Steps 🪜

### To find Area and Perimeter of Square and Rectangle

- Display a message to the user and accept the side of square. Again, display a message to the user and accept the length and width of the rectangle.
- Since, we know the formula to find the area of square (
) and to find the perimeter of square (`s * s`

). We can directly display the results with the help of printf() statements.`4 * s`

- Same way, by using printf() statements, we display the area and perimeter of rectangle with the help of their formulas
and`l * w`

, respectively.`2 * (l + w)`

## Flow Chart 🌻

Check how to draw the flow chart for this program.

## Code 💻

```
#include <stdio.h>
#include <conio.h>
int main()
{
float s=0, l=0, w=0;
printf("Please enter the side of square: ");
scanf("%f", &s);
printf("Please enter the length and width of rectangle:\n");
scanf("%f%f", &l, &w);
// Area and Perimeter of Square
printf("\n\nSquare:\n");
printf("Area: %0.2f", s * s);
printf("\nPerimeter: %0.2f", 4 * s);
// Area and Perimeter of Rectangle
printf("\n\nRectangle:\n");
printf("Area: %0.2f", l * w);
printf("\nPerimeter: %0.2f", 2 * (l + w));
return 0;
}
```

## Example 😍

Let’s assume that the user enters the side of square as 4 and length, width of rectangle as 5 and 6, respectively.

First, it will display the area and perimeter of **square** as 16 and 16, respectively. Next, it will display the area and perimeter of **rectangle** as 30 and 22, respectively.

The output will be like this:

```
Square:
Area: 16.00
Perimeter: 16.00
Rectangle:
Area: 30.00
Perimeter: 22.00
```

This is how we find out the area and perimeter of square and rectangle. For more C Programs, click here.

## Comments