Find Perimeter of a triangle

Last Updated : 7 Feb, 2026

Given side (a, b, c) of a triangle, we have to find the perimeter of a triangle. 

Perimeter : 
Perimeter of a triangle is the sum of the length of side of a triangle. 
 

Perimeter of a triangle


where a, b, c are length of side of a triangle.
Perimeter of a triangle can simply be evaluated using following formula : 
perimeter = (a + b + c)  

Examples :  

Input : a = 2.0, b = 3.0, c = 5.0
Output : 10.0


Input : a = 5.0, b = 6.0, c = 7.0
Output : 18.0
C++
// A simple C++ program to find the perimeter
// of triangle
#include <iostream>
using namespace std;

// Function to find perimeter
float findPerimeter(float a, float b, float c)
{
    
    // Formula for finding a perimeter
    // of triangle
    return (a + b + c);
}

// Driver Code
int main() 
{
    float a = 2.0, b = 3.0, c = 5.0;
    cout << findPerimeter(a, b, c);  
    return 0;
}

// This code is contributed by Ankita saini
Java
// A simple Java program to find the perimeter
// of triangle
public class Main {
    // Function to find perimeter
    public static float findPerimeter(float a, float b, float c) {
        // Formula for finding the perimeter of triangle
        return (a + b + c);
    }

    public static void main(String[] args) {
        float a = 2.0f, b = 3.0f, c = 5.0f;
        System.out.println(findPerimeter(a, b, c));
    }
}

// This code is contributed by Ankita saini
Python
# Python Program to find a perimeter
# of triangle

# Function to find perimeter
def findPerimeter(a, b, c):

    # Calculate the perimeter
    return (a + b + c)

# Driver Code    
a = 2.0
b = 3.0
c = 5.0
print(findPerimeter(a, b, c))
C#
// A simple C# program to find the perimeter
// of triangle
using System;

class Program {
    // Function to find perimeter
    static float FindPerimeter(float a, float b, float c) {
        // Formula for finding the perimeter of triangle
        return a + b + c;
    }

    static void Main() {
        float a = 2.0f, b = 3.0f, c = 5.0f;
        Console.WriteLine(FindPerimeter(a, b, c));
    }
}

// This code is contributed by Ankita saini
JavaScript
// A simple JavaScript program to find the perimeter
// of triangle

// Function to find perimeter
function findPerimeter(a, b, c) {
    // Formula for finding the perimeter of triangle
    return a + b + c;
}

// Driver Code
let a = 2.0, b = 3.0, c = 5.0;
console.log(findPerimeter(a, b, c));

// This code is contributed by Ankita saini

Output : 

10.0

Time Complexity: O(1)

Auxiliary Space: O(1)

Comment