logo image

C++ program to calculate square area and circumference

Views: 15

Following program shows you how to calculate square area and circumference. This program gets square length from user and calculates area and circumference and prints them using following formulas Area = length X length Circumference = 4 X length

#include <iostream>
#include <math.h>

int main() {
	float squareLength;

	std::cout << "Enter length of square:";
	std::cin >> squareLength;

	float areaOfSquare = squareLength * squareLength;

	std::cout << "Area of square is: " << areaOfSquare << "\n";

	float circumferenceOfSquare = 4 * squareLength;

	std::cout << "Circumference of square is: " << circumferenceOfSquare;
}

Output:

Enter length of square: 18
Area of square is: 324
Circumference of square is: 72