logo image

C++ program to calculate triangle circumference


Following program shows you how to calculate triangle circumference. This program gets triangle sides from user and calculates circumference and prints it using following formula Circumference = side1 + side2 + side3

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

int main() {
	float triangleSide1;
	float triangleSide2;
	float triangleSide3;

	std::cout << "Enter the side1 of triangle:";
	std::cin >> triangleSide1;

	std::cout << "Enter the side2 of triangle:";
	std::cin >> triangleSide2;

	std::cout << "Enter the side3 of triangle:";
	std::cin >> triangleSide3;

	float circumferenceOfTriangle =
		triangleSide1 + triangleSide2 + triangleSide3;

	std::cout << "Circumference of triangle is: " << circumferenceOfTriangle;


Enter the side1 of triangle: 12
Enter the side2 of triangle: 15
Enter the side3 of triangle: 18
Circumference of triangle is: 45