Perimeter of parallelogram

Write a program to find the perimeter of the parallelogram.

Example 1:

Input: side1=4,side2=5
Output: 18

Approach: Given parallel sides. 

Perimeter is 2*(side1+side2)

Java


public class PerimeterofParallelogram {
    public static void main(String[] args) {
        // one parallel side
        double side1 = 4;
        // another parallel side
        double side2 = 5;
        double perimeter = perimeterParallelogram(side1, side2);
        System.out.println("Perimeter of Parallelogram is " + perimeter);
    }

    private static double perimeterParallelogram(double side1double side2) {
        return 2 * (side1 + side2);
        
    }
}

C++

#include <bits/stdc++.h>
using namespace std;
//function to find the  perimeter
//of the parallelogram
double perimeterParallelogram(double side1,double side2)
{
    double perimeter=2*(side1+side2);
    return perimeter;
}
int main()
{
    //one parallel side
    double side1=4;
    //another paralle side
    double side2=5;
    double perimeter=perimeterParallelogram(side1,side2);
    cout<<"Perimeter of Parallelogram is ";
    cout<<perimeter<<"\n";
    return 0;
}


No comments:

Post a Comment