Find the Area and Perimeter of Square and Rectangle. Input 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 & width of rectangle.
- Since we know the formula to find the area of square (s * s) and to find the perimeter of square (4 * s). We can directly display the results with the help of printf() statements.
- Same way, by using printf statements, we display the area and perimeter of rectangle with the help of their formulas l * w and 2 * (l + w), respectively.

## Flow Chart 🌻

Check how to draw flow chart for this program.

## Code 💻

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

## Example 😍

Let’s assume, 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. Next, it will display the area and perimeter of rectangle as 30 and 22.

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.