Q:

Write a Program to calculate the Area of Rhombus

belongs to collection: Miscellaneous Programs Examples

0

Before writing the program of calculating the area of rhombus in different programming languages, firstly we have to know about what is rhombus and what is the formula to find area of it?

What is Rhombus?

A rhombus is a polygon, whose all four sides is equal in length and opposite side is parallel.

Area of Rhombus = ( d1 * d2 ) / 2  

Where, d1 and d2 are the two diagonals of rhombus.   

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program of calculating the area of a rhombus in different Programming languages

Program 1: Write a Program in C language:

// This a C program which uses a function to find the area of a rhombus.  
#include <stdio.h> // Function to find area   
float findAreaofrhombus(float d1, float d2)   
{   
float Area_of_rhombus;  
Area_of_rhombus= ( d1 * d2 ) / 2; // It is a formula for calculating a area of rhombus   
return (Area_of_rhombus);   
}   
int main()   
{   
float d1, d2;   
printf("Enter the 1st diagonal of the rhombus:");   
scanf("%f",&d1);  
printf("Enter the 2nd diagonal of the rhombus:");  
scanf("%f",&d2);  
printf("Area of the rhombus is: %.2f", findAreaofrhombus(d1, d2));     
return 0;   
}  

 

Output of Above C program:

Enter the 1st diagonal of the rhombus:5
Enter the 2nd diagonal of the rhombus:10
Area of the rhombus is: 25.0

 

Program 2: Write a Program in Java language:

// This a  Java program which calculates the area of a rhombus.  
class findarea {   
static int findAreaofrhombus(int d1, int d2)   
{   
int Area_of_rhombus;  
Area_of_rhombus= ( d1 * d2 ) / 2; // It is a formula for calculating the area of rhombus   
return(Area_of_rhombus);   
}   
  
// Driver method   
public static void main(String[] args)   
{   
int d1 = 20;  
int d2 = 40;   
System.out.println("The Area of a rhombus in Java:");  
System.out.println(findAreaofrhombus(d1, d2));   
}   
}  

 

Output of Above Java program:

The Area of a rhombus in Java:
400

 

Program 3: Write a Program in PHP programming language.

<?php   
// This a  PHP program which calculates the area of a rhombus.    
// Function to find area   
function findAreaofrhombus($d1, $d2)   
{           
$Area_of_rhombus = ( $d1 * $d2 ) / 2; // It is a formula which calculates the area  and store the value in the area variable.   
return ($Area_of_rhombus);   
}   
  
$d1 = 80;    
$d2= 30;   
  
echo findAreaofrhombus($d1, $d2);   
  
?>  

 

Output of Above PHP program:

1200

 

Program 4: Write a Program in Python programming language.

# This is a python program which calculates the area of a rhombus.   
# It is a function to calculate the area of rhombus  
def findAreaofrhombus(d1, d2):  
    return ( ( d1 * d2 ) / 2) # It is a formula which adds the three side and # then return the value to the statement of calling fucntion.   
d1 =30  
d2= 40  
print(findAreaofrhombus(d1,d2))  

 

Output of Above Python program:

600.0

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Miscellaneous Programs Examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a Program to calculate the surface Area of C... >>
<< Write a Program to calculate the Perimeter of Hexa...