write a program to input length and breadth of a rectangle to calculate and display it's area and perimeter using switch case statement
Answers
Answer:
Explanation:
#include <stdio.h>
/* height and width of a rectangle in inches */
int width;
int height;
int area;
int perimeter;
int main() {
height = 7;
width = 5;
perimeter = 2*(height + width);
printf("Perimeter of the rectangle = %d inches\n", perimeter);
area = height * width;
printf("Area of the rectangle = %d square inches\n", area);
return(0);
}
Answer:
import java.util.*;
public class Menu
{
public static void main {String args[] }
{
Scanner in = new Scanner (System.in)
int l, b , n, a , p;
double d;
System.out.println( "Enter length and breadth of a rectangle");
a = in.nextInt();
b = in.nextInt();
System.out.println( "Enter 1 for area, 2 for perimeter, 3 for diagonal);
System.out.println("Enter your choice");
n = in.nextInt();
switch (n)
{
case 1:
a = l*b;
System.out.println("Area of rectangle =" +l);
break;
case 2:
p = 2(l+b);
System.out.println("Perimeter of rectangle =" +p);
break;
case 3;
d = Math.sqrt(l*l + b*b);
System.out.println("Diagonal of rectangle =" +d);
break;
default:
System.out.println(" wrong choice !!");
}
}
}