TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Program to find the perimeter of the rectangle

Program to find the perimeter of the rectangle on fibonacci, factorial, prime, armstrong, swap, reverse, search, sort, stack, queue, array, linkedlist, tree, graph etc.

<< Back to PROGRAM

Program to find the perimeter of the rectangle

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)


Solution

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

Next Topic#




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf