Q:

Program to find the perimeter of the rectangle

belongs to collection: Basic Programs

0

Explanation

A rectangle has four sides in which sides opposite to each other are equal. The perimeter of the rectangle is the area around its outside.

Suppose a, b, c, d are the four sides of rectangle.

a=c and b=d

Perimeter Of Rectangle= a+ b+ c+ d= a+ b+ a+ b= 2(a + b).

Algorithm

  1. Define Values for the side of the rectangle
  2. Apply values in the formula.
  3. Print the Perimeter.

Complexity

O(1)

Input:

a = c = 5  

b = d = 4  

Output:

Perimeter of Rectangle = 2 * ( a + b);
                       = 2 * (5 + 4)
                       = 18.00000

All Answers

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

Python

a=c=2 # in rectangle sides opposite to each other are equal in length  
b=d=4 # length of opposite sides  
Perimeter = 2*(a+ b)  
print("Perimeter of rectangle is: ");  
print(Perimeter);   

 

Output:

Perimeter of Rectangle is:  12

 

C

#include<stdio.h>  
                   int main()   
                   { float a , b, c, d ,perimeter;  
                a= c= 5;  
                                     b=d= 4;  
                   perimeter = 2*(a+b);  
                                  printf("\n\n Perimeter of Rectangle is : %f",perimeter);  
                       return (0);  
    }  

 

Output:

Perimeter of Rectangle is: 18.00000

 

JAVA

public class Main  
 {  
   public static void main (String args[])  
    {      float a ,b, c, d, perimeter;  
                    a=c= 5;  
                    b=d=4;  
                    perimeter  = 2*(a+b);  
            System.out.println("Perimeter of Rectangle is: "+perimeter);  
    }}  

 

Output:

Perimeter of Rectangle is: 18.0

 

C#

using System;  
class main  
{   static void Main()   
    {  
      float  a , b, c, d, perimeter;  
      a=c=3;  
      b=d=6;  
   
     perimeter =2*(a+b);  
    Console.WriteLine("Perimeter of Rectangle is: "+perimeter);  
    }}  

 

Output:

Perimeter of Rectangle is: 18

 

PHP

<?php  
       $a = $c=5 ;  
       $b = $d=6 ;  
       $Perimeter = 2*($a + $b);  
       echo("Perimeter of Rectangle is: ");  
       echo($Perimeter);  
?>  

 

Output:

Perimeter of Rectangle is: 22

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

total answers (1)

Program to find the simple interest... >>
<< Program to find the area of the right angle triang...