Perimeter of Rectangle: C Program


The length and breadth / width of a rectangle are entered through the keyboard. Write a program to calculate the perimeter of the rectangle.

To get perimeter of a rectangle, we add the length and width of rectangle and then multiply it with 2. In other words, perimeter is the addition of length of all the sides of a rectangle.

Related Read:
Basic Arithmetic Operations In C
Area of Rectangle: C Program

Note: Perimeter of a Rectangle is calculated using the formula
Perimeter = 2 * (Length + Width);


perimeter of rectangle

Length: is the length of the longest side of the rectangle.
width: is the length of the smallest side of the rectangle.

Find Perimeter of a Rectangle: C Program


[youtube https://www.youtube.com/watch?v=EnQTDhvimd0]

YouTube Link: https://www.youtube.com/watch?v=EnQTDhvimd0 [Watch the Video In Full Screen.]


Source Code: Find Perimeter of a Rectangle: C Program

  1. #include < stdio.h >  
  2.   
  3. int main()  
  4. {  
  5.     float length, width, perimeter;  
  6.   
  7.     printf("Enter length of Rectangle\n");  
  8.     scanf("%f", &length);  
  9.   
  10.     printf("Enter width of Rectangle\n");  
  11.     scanf("%f", &width);  
  12.   
  13.     perimeter = 2 * (length + width);  
  14.   
  15.     printf("Perimeter of Rectangle is %f\n", perimeter);  
  16.   
  17.     return 0;  
  18. }  

Output:
Enter length of Rectangle
12
Enter width of Rectangle
6
Perimeter of Rectangle is 36.000000

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Leave a Reply

Your email address will not be published. Required fields are marked *