Computer Science, asked by rubinasahu170, 1 month ago

write a program to find the area of rectangle ,circle and square in switch case ?

Answers

Answered by anjalirehan04
2

This is a C program to find area of a rectangle, circle and triangle.

#include <stdio.h>

#include <conio.h>  

#include <stdlib.h>  

#include <math.h>  

void main()

{

int a,b,c,r, rectarea;

float circlearea, s1,s2,s3;

float s,triarea2;

clrscr();

printf("n Three Choices");

printf("n…………………….n 1- rectanglen 2- circlen 3- triangle");

printf("n Enter your choice :");

scanf("%d",&c);

switch(c)

{

case 1:  

 printf("n Enter breadth and length of rectangle:");

scanf("%d%d",&a,&b);

rectarea = a * b;

printf("Area of rectangle with breadth %d and length %d is %d units",a,b,      rectarea);

break;

case 2:

printf("n Enter the radius of circle:");

scanf("%d",&r);

circlearea = 3.14 * r * r;

printf("Area of triangle with radius %d is %f units ",r, circlearea);

break;

case 3:

printf("n Enter the three side of triangle:n");

scanf("%f%f%f",&s1,&s2,&s3);

s = (s1 + s2 + s3)/2;

triarea2 =sqrt(s *((s - s1) * (s - s2) * (s - s3)));

printf("Area of triangle is %f",triarea2);

break;

default:

printf("Invalid choice");

}

getch();

}

please mark me brain mark list

Answered by Anonymous
1

import java.util.Scanner;

public class Switchcase

{

   public static void main(String[] args)

   {

       Scanner input = new Scanner(System.in);

       double area;

       double length, breadth,side, radius;

       int choice;

       

       System.out.println("1. Area of Square");

       System.out.println("2. Area of Rectangle");

       System.out.println("3. Area of Circle");

       

       area = 0.0;

       length = 0.0;

       breadth = 0.0;

       side = 0.0;

       radius = 0.0;

       

       System.out.println("Enter your choice (1 - 3): ");

       choice = input.nextInt();

       

       switch(choice)

       {

           case 1:

               System.out.println("Enter the side of the square: ");

               side = input.nextDouble();

               

               area = side * side;

               

               System.out.println("The area of a square with side " + side +

                   " is = " + area);

               break;

               

           case 2:

               System.out.println("Enter the length of the rectangle: ");

               length = input.nextDouble();

               

               System.out.println("Enter the breadth of the rectangle: ");

               breadth = input.nextDouble();

               

               area = length * breadth;

               

               System.out.println("The area of a rectangle with length " + length +

                   " and breadth " + breadth + " is = " + area);

               break;

               

           case 3:

               System.out.println("Enter the radius of the circle: ");

               radius = input.nextDouble();

               

               area = 2.0 * Math.PI * radius * radius;

               

               System.out.println("The area of a circle with radius " + radius +

                   " is = " + area);

               break;

               

           default:

               System.out.println("Invalid Input.");

       }

   }

}

Similar questions