Q:

Write a program to calculate the Perimeter of a Rhombus

0

In this article, we are going to discuss the program to find the perimeter of a rhombus in different programming languages.

But before writing the programs, let's first see a brief description of a rhombus and the formula to find its perimeter.

What is a Rhombus?

A rhombus is a kind of quadrilateral and also the parallelogram's special case. It is in a diamond shape. The opposite sides of a rhombus are parallel, and their opposite angles are equal.

Perimeter of rhombus

The perimeter of the rhombus is the sum of all four sides.

The formula for calculating the perimeter of a rhombus is -

 

Perimeter of rhombus = 4 x a units (Where 'a' is the side of rhombus)  

Now, let's see the programs for calculating the perimeter of a rhombus.

All Answers

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

Programs of calculating the perimeter of a rhombus

Program: Write a program to calculate the perimeter of the rhombus in C language.

#include <stdio.h>   
float perimeterRhombus(float a)     
{     
float perimeter;    
perimeter = 4 * a; // formula for calculating the perimeter of rhombus     
return (perimeter);     
}     
int main()     
{     
float a;     
printf("Enter the side of rhombus:");     
scanf("%f", &a);    
printf("perimeter of rhombus is: %f", perimeterRhombus(a));       
return 0;     
}    

Output:

 

Program: Write a program to calculate the perimeter of rhombus in the Java language.

import java.util.*;  
class Rhombus {     
static int perimeterRhombus(int a)     
{     
int perimeter;    
perimeter = 4 * a; //formula for calculating the perimeter of rhombus     
return(perimeter);     
}     
public static void main(String[] args)     
{     
Scanner sc = new Scanner(System.in);      
System.out.println("Enter the side of Rhombus:");  
int a = sc.nextInt();  
System.out.println("Perimeter of a rhombus is:");    
System.out.println(perimeterRhombus(a));     
}     
}    

Output:

After the execution of the above code, the output will be -

 

Program: Write a program to calculate the perimeter of rhombus in C#.

using System;  
class HelloWorld {  
    static int perimeterRhombus(int a)  
{  
    int perimeter;  
    perimeter = 4 * a;  
    Console.WriteLine("The perimeter of rhombus " +  
                      "with side " + a + " is " + perimeter + ".");  
        return 0;  
}  
  public static void Main() {  
    int side;  
      Console.Write("Enter side of Rhombus: ");  
      side = Convert.ToInt32(Console.ReadLine());  
      perimeterRhombus(side);  
        
  }  
}  

Output:

 

Program: Write a program to calculate the perimeter of rhombus in PHP.

<?php     
// It is a PHP program to calculate the perimeter of a Rhombus  
function perimeterRhombus($a)     
{             
$perimeter = 4 * $a; // It is a formula to the perimeter and store the result in the perimeter variable.     
return ($perimeter);     
}     
$side = 20;  
echo perimeterRhombus($side);     
?>    
</html>  

Output:

80

 

Program: Write a program to calculate the perimeter of rhombus in Python.

def perimeterRhombus(a):    
    return (4 * a)  
      
side = int(input('Enter the side of Rhombus:'))  
perimeter = perimeterRhombus(side)  
print(perimeter)  

Output:

 

Program: Write a program to calculate the perimeter of rhombus in JavaScript.

<script>  
// javascript Program to calculate perimeter of a rhombus using side  
function perimeterRhombus(a)  
{  
    let perimeter;  
    perimeter = 4 * a;  
    document.write("The perimeter of rhombus with side " + a + " is " + perimeter + "." + "<br>");  
}  
    let side = 5;  
    perimeterRhombus(side);  
</script>  

Output:

So, that's all about the article. Here, we have discussed the programs to calculate the perimeter of rhombus using its side in C, Java, C#, PHP, python, and JavaScript.

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

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now