C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
| Program to find the perimeter of the rectangle
 ExplanationA 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
 ComplexityO(1) SolutionPython
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 
Next Topic#
 |