C Program to Find the Perimeter of a Square

Write a C program to find the perimeter of a square. This example allows entering the square side and uses the (4 * side) math formula to calculate the perimeter.

#include <stdio.h>

int main()
{
    float Sqrside, Sqrperimeter;
    
    printf("Enter the Square Side = ");
    scanf("%f",&Sqrside);

    Sqrperimeter = 4 * Sqrside;

    printf("The perimeter of a Square = %.2f\n", Sqrperimeter); 
    
    return 0;
}
Perimeter of a Square

In this program, the user defined function accepts the side and finds the perimeter of a square.

#include <stdio.h>

float squarePerimeter(float Sqrside)
{
    return 4 * Sqrside;
}
int main()
{
    float Sqrside, Sqrperimeter;
    
    printf("Enter the Side = ");
    scanf("%f",&Sqrside);

    Sqrperimeter = squarePerimeter(Sqrside);

    printf("The perimeter = %.2f\n", Sqrperimeter); 
    
    return 0;
}
Enter the Side = 14
The perimeter = 56.00


Enter the Side = 9
The perimeter = 36.00

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.