Write a java program to find the area for the following. Area of rhombus =1/2*diagonal1*diagonal 2. Area of trapezium =1/2*height *(a+b). Area of circle =pie*r*r
Answers
Answer:
// C++ program to calculate the area of a rhombus
// whose one side and one diagonal is given
#include<bits/stdc++.h>
using namespace std;
// function to calculate the area of the rhombus
double area(double d1, double a)
{
// Second diagonal
double d2 = sqrt(4 * (a * a) - d1 * d1);
// area of rhombus
double area = 0.5 * d1 * d2;
// return the area
return area;
}
// Driver code
int main()
{
double d = 7.07;
double a = 5;
printf("%0.8f", area(d, a));
}
import java.util.*;
public class Area
{
public static void main (String args[])
{
Scanner in= new scanner (System.in);
int d1,d2, h, a , b, rd;
double r, t, c;
System.out.println("enter the values of the diagonals of rhombus, the values of the parallel sides and height of trapezium and the radius of the circle :");
d1 = in.nextInt();
d2 = in.nextInt();
h = in.nextInt();
a = in.nextInt();
b = in.nextInt();
rd = in.nextInt();
r = (1/2*d1*d2);
t = (1/2*h*(a+b));
c = (22/7*r*r);
System.out.println("Area of rhombus = " +r );
System.out.println("Area of trapezium =" +t );
System.out.println("Area of circle =" +c);
}
}