C++ Program to Find Perimeter of a Square

Howdy readers, today you will learn how to write a C++ program to find the perimeter of a square.

The perimeter of a square is defined as the length that its boundary covers. The formula to calculate the perimeter of a square is given as: P = 4 x length of one side.

This tutorial prompts the user to enter the side of a square, then it computes the perimeter using the mathematical formula:

  • Perimeter of Square = 4 x Side

So, without any delay, let’s begin this tutorial.

C++ Program to Find Perimeter of a Square

C++ Program

// C++ Program to Find Perimeter of a Square
#include <iostream>
using namespace std;

int main(){
    int side, pm;
    
    // Taking input
    cout << "Enter the side of the square: ";
    cin >> side;
    
    // Calculating perimeter of square
    pm = 4 * side;
    
    // Display perimeter
    cout << "The perimeter of the square is: " << pm << endl;
    
    return 0;
}

Output

Enter the side of the square: 15
The perimeter of the square is: 60
C++ Program to Find Perimeter of a Square

Explanation

    int side, pm;

We have declared two int data type variables named side and pm in this program.

    cout << "Enter the side of the square: ";
    cin >> side;

The side of the square is taken as input from the user. The entered value gets stored in the side named variable.

    pm = 4 * side;

The perimeter of the square is calculated using the formula: Perimeter of square = 4 x side. The perimeter gets stored in the pm named variable.

    cout << "The perimeter of the square is: " << pm << endl;

At last, the perimeter of the square is printed on the screen using the cout statement.

Conclusion

Today you learned how to write a C++ program to find the perimeter of a square.

If you have any queries related to the tutorial, comment down your queries in the comment section.

Thanks for reading.

Happy Coding!!

Also Read:

Leave a Comment