C Program to find Perimeter of a Rectangle using length and width

Write a C Program to find the Perimeter of a Rectangle using length and width with an example. If we know the length and width, we can calculate the perimeter of a rectangle using the formula: Perimeter = 2 * (Length + Width).

This C program allows the user to enter the length and width of a rectangle. Using those values, this Programming code will calculate the Perimeter of a rectangle.

#include<stdio.h>
int main()
{
  	float width, length, Perimeter; 
 
  	printf ("\n Please Enter the Width of a Rectangle  :  ");
  	scanf ("%f",&width);

  	printf ("\n Please Enter the Length of a Rectangle :  ");
  	scanf ("%f",&length);
	   
  	Perimeter = 2 * (length + width);
 
	printf("\n Perimeter of a Rectangle =  %.2f", Perimeter);
 
  	return 0;
}
Program to find Perimeter of a Rectangle using length and width

The following program calculates the perimeter of a Rectangle using functions.

#include <stdio.h>

float findRecPeri(float length, float breadth)
{
return 2 * (length + breadth);
}
int main()
{
float l, b;

printf("Enter Length and Breadth = ");
scanf("%f %f", &l, &b);

printf("Perimeter Of a Rectangle = %.2f", findRecPeri(l, b));
}
Enter Length and Breadth = 22 30
Perimeter Of a Rectangle = 104.00

Also Read