C Program to Find Perimeter of a Rectangle

C Program to Find Perimeter of a Rectangle

C program to find the perimeter of a rectangle; Through this tutorial, we will learn how to find or calculate perimeter of a rectangle using standard formula, function and pointer in c programs.

Programs and Algorithm to Find Perimeter of a Rectangle

Use the following algorithm and programs to find or calculate perimeter of a rectangle using standard formula, function and pointer in c:

  • Algorithm to Find Perimeter of a Rectangle
  • C Program to Find Perimeter of a Rectangle using Formula
  • C Program to Find Perimeter of a Rectangle using Function
  • C Program to Find Perimeter of a Rectangle using Pointer

Algorithm to Find Perimeter of a Rectangle

Use the following algorithm to write a program to find the perimeter of rectangle; as follows:

  1. Take input length and width of rectangle. Store it in two different variables.
  2. Calculate perimeter of rectangle using perimeter=2*(length+breadth)
  3. Finally, print the value of perimeter of rectangle.

C Program to Find Perimeter of a Rectangle using Formula

#include<stdio.h>
int main()
{
	float length,breadth,perimeter;
	
	printf("enter length of rectangle: ");
	scanf("%f",&length);
	
	
	printf("enter breadth of rectangle: ");
	scanf("%f",&breadth);
 
	perimeter=2*(length+breadth);
	printf("Perimeter of Rectangle: %f\n",perimeter);
	return 0;
}

The output of the above c program; as follows:

enter length of rectangle: 10
enter breadth of rectangle: 50
Perimeter of Rectangle: 120.000000

C Program to Find Perimeter of a Rectangle using Function

float perimeter(float l,float b)
{
	return 2*(l+b);
}
 
int main()
{
	
	float l,b,p;
	
	printf("enter length of rectangle: ");
	scanf("%f",&l);
	
	
	printf("enter breadth of rectangle: ");
	scanf("%f",&b);
 
	p=perimeter(l,b);
	printf("Perimeter of Rectangle: %f\n",p);
	return 0;
}

The output of the above c program; as follows:

enter length of rectangle: 10
enter breadth of rectangle: 66
Perimeter of Rectangle: 152.000000

C Program to Find Perimeter of a Rectangle using Pointer

#include<stdio.h>
void perimeter(float *l,float *b,float *p)
{
	*p=2*(*l+*b);
}
 
int main()
{
    
float l,b,p;
	
	printf("enter length of rectangle: ");
	scanf("%f",&l);
	
	
	printf("enter breadth of rectangle: ");
	scanf("%f",&b);
 
	perimeter(&l,&b,&p);
	printf("Perimeter of Rectangle: %f\n",p);
	return 0;
}

The output of the above c program; as follows:

enter length of rectangle: 55
enter breadth of rectangle: 65
Perimeter of Rectangle: 240.000000

Recommended C Programs

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

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