Perimeter of tringle

Write a program to find the perimeter of the triangle.

Example 1:

Input: side1=4,side2=3,side3=5
Output: 12

Approach: Given sides of the triangle. 

Perimeter is the sum of all sides. i.e (a+b+c).

Java

public class PerimeterofTringle {
    public static void main(String[] args) {
        double side1 = 4;
        double side2 = 3;
        double side3 = 5;
        double perimeter = perimeterTriangle(side1, side2, side3);
        System.out.println("Perimeter of Tringle is " + perimeter);
    }

    private static double perimeterTriangle(double side1double side2double side3) {
        return side1 + side2 + side3;
    }
}

C++

#include <bits/stdc++.h>
using namespace std;
//function to find the perimeter of
//triangle
double perimeterTriangle(double a ,double b,double c)
{
    double perimeter=a+b+c;
    return perimeter;
}
int main()
{
    double side1=4;
    double side2=3;
    double side3=5;
    double perimeter=perimeterTriangle(side1,side2,side3);
    cout<<"Perimeter of triange is ";
    cout<<perimeter<<"\n";
    return 0;
}


No comments:

Post a Comment