Perimeter of rhombus

Write a program to find the perimeter of the rhombus.

Example:

Input: side=8
Output: 32

Approach: Given side of rhombus. 

Perimeter is 4*(side)

Java

public class PerimeterofRhombus {
    public static void main(String[] args) {
        double side = 8;
        double perimeter = perimeterRhombus(side);
        System.out.println("Perimeter of rhombus is " + perimeter);
    }

    private static double perimeterRhombus(double side) {
        return 4 * side;
    }
}

C++

#include <bits/stdc++.h>
using namespace std;
//function to find the perimeter
//of rhombus
double perimeterRhombus(double side)
{
    double perimeter=4*side;
    return perimeter;
}
int main()
{
    double side=8;
    double perimeter=perimeterRhombus(side);
    cout<<"Perimeter of rhombus is ";
    cout<<perimeter<<"\n";
    return 0;
}


No comments:

Post a Comment