Area OR Perimeter Codechef Solution|Problem Code: AREAPERI

Area OR Perimeter Codechef Solution

Problem

Write a program to obtain length (L) and breadth (B) of a rectangle and check whether its area is greater or perimeter is greater or both are equal.

Input:

  • First line will contain the length (L) of the rectangle.
  • Second line will contain the breadth (B)of the rectangle.

Output:

Output 2 lines.

In the first line print “Area” if area is greater otherwise print “Peri” and if they are equal print “Eq”.(Without quotes).

In the second line print the calculated area or perimeter (whichever is greater or anyone if it is equal).

Constraints

  • 1≤L≤10001≤L≤1000
  • 1≤B≤1000

Example

Sample Input 1 

1
2

Sample Output 1 

Peri
6

Area OR Perimeter – CodeChef Solution in JAVA

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int L = sc.nextInt();
		int B = sc.nextInt();
		System.out.println(solve(L, B));
		sc.close();
	}
	static String solve(int L, int B) {
		int area = L * B;
		int perimeter = (L + B) * 2;
		String comparison;
		if (area > perimeter) {
			comparison = "Area";
		} else if (area < perimeter) {
			comparison = "Peri";
		} else {
			comparison = "Eq";
		}
		return String.format("%s\n%d", comparison, Math.max(area, perimeter));
	}
}

Area OR Perimeter – CodeChef Solution in CPP

#include <iostream>
using namespace std;
int main() {
	// your code goes here
	float l,b,area,peri;
	cin>>l>>b;
	area=l*b;
	peri=2*(l+b);
	    if(area>peri){
	        cout<<"Area"<<endl;
	        cout<<area;
	    }else if(peri>area){
	        cout<<"Peri"<<endl;
	        cout<<peri;
	    }else if(area==peri){
	        cout<<"Eq"<<endl;
	        cout<<area;
	    }
	return 0;
}

Area OR Perimeter – CodeChef Solution in Python

l = int(input())
b = int(input())
a = l*b
p = 2*l+2*b
if a>p:
    print("Area")
    print(a)
elif a==p:
    print("Eq")
    print(a)
else:
    print("Peri")
    print(p)

Disclaimer: The above Problem (Area OR Perimeter) is generated by CodeChef but the solution is provided by  Chase2learn.This tutorial is only for Educational and Learning purpose.

Leave a Comment