C Program to Find the Perimeter of a Square

C Program to Find the Perimeter of a Square

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

Programs and Algorithm to Find Perimeter of a Square

Let’s use the following algorithm and program to find or calculate perimeter of a square using standard formula, function, and pointer in c:

  • Algorithm to Find Perimeter of a Square
  • C Program to Find Area Of SemiCircle using Standard Formula
  • C Program to Find Area Of SemiCircle using Function
  • C Program to Find Area Of SemiCircle using Pointer

Algorithm to Find Perimeter of a Square

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

  1. Take input side of square. Store it in variable.
  2. Calculate perimeter of square using perimeter=4*side;;
  3. Finally, print the value of perimeter of square.

C Program to Find Perimeter of a Square using Standard Formula

#include<stdio.h>
int main()
{
	float side,perimeter;
	printf("enter side of square: ");
	scanf("%f",&side);
	
 
	perimeter=4*side;
	printf("Perimeter Of Square: %f\n",perimeter);
	return 0;
}

The output of the above c program; as follows:

enter side of square: 5
Perimeter Of Square: 20.000000

C Program to Find Perimeter of a Square using Function

 #include<stdio.h>
float perimeter(float s)
{
	return (4*s);
}
 
int main()
{
	float s,p;
	
	printf("enter side of square: ");
	scanf("%f",&s);
	
	p=perimeter(s);
	printf("Perimeter Of Square: %f\n",p);
	return 0;
}

The output of the above c program; as follows:

enter side of square: 10
Perimeter Of Square: 40.000000

C Program to Find Perimeter of a Square using Pointer

#include<stdio.h>
void perimeter(float *s,float *p)
{
	*p=((4)*(*s));
}
 
int main()
{
    
	float s,p;
	
	printf("enter side of square: ");
	scanf("%f",&s);	
 
	perimeter(&s,&p);
	printf("Perimeter of a Square: %f\n",p);
	return 0;
}

The output of the above c program; as follows:

enter side of square: 9
Perimeter of a Square: 36.000000

Recommended C Programs

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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