Area of rectangle

Write a program to find the area of the rectangle.

Example 1:

Input: length=12,width=5
Output: 60

Example 2:

Input: length=3,width=4
Output:12

Approach: Given the length and width of the rectangle. 

Formula: Area = length*width

Java

public class AreaofRectangle {
    public static void main(String[] args) {
        double length = 12;
        double width = 5;
        double area = areaRectangle(length, width);
        System.out.println("Area of Rectangle is " + area);
    }

    private static double areaRectangle(double lengthdouble width) {
        return length * width;
    }
}

C++

#include <bits/stdc++.h>
using namespace std;
//function to find the area of
//rectangle
double areaRectangle(double length,double width)
{
    return length*width;
}
int main()
{
    double length=12;
    double width=5;
    double area=areaRectangle(length,width);
    cout<<"Area of rectangle is ";
    cout<<area<<"\n";
    return 0;
}


No comments:

Post a Comment