 C Tutorial

# C Program to Compute Perimeter of Square

## C program to find the perimeter of a square

This c porgram is used to compute the perimeter of a square based on user input length.

Length is equal for each side in square.

## Formula to compute perimeter of a square

```Perimeter of a square: length + length + length + length
```
or
```Perimeter of a square: 4 x length
```

## C program to calculate the perimeter of a square

```// Finds perimeter of a triangle
#include<stdio.h>

void main()
{
int length, perimeter=0;
printf("\nFinds perimeter of a square\n-------------------");
printf("\nEnter Length: ");
scanf("%d", &length);

perimeter = 4 * length;

printf("Perimeter of a square is: %d", perimeter);
}
```

Output:

```\$ cc perimeter-of-square.c
\$ ./a.out

Finds perimeter of a square
-------------------
Enter Length: 6
Perimeter of a square is: 24
```

## Other way to implement using addition operator

```#include<stdio.h>

void main()
{
int length, perimeter=0;
printf("\nFinds perimeter of a square\n-------------------");
printf("\nEnter Length: ");
scanf("%d", &length);

perimeter = (length + length + length + length);

printf("Perimeter of a square is: %d", perimeter);
}
```

Output:

```\$ cc perimeter-of-square.c
\$ ./a.out

Finds perimeter of a square
-------------------
Enter Length: 6
Perimeter of a square is: 24
``` C Tutorial

## C Examples

Privacy Policy  |  Copyright 2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page     