C Program to Calculate Square of a Number

How to write a C Program to Calculate Square of a Number using Functions with an example?.

C Program to Calculate Square of a Number

This program allows the user to enter an integer value and then finds the square of that number using the Arithmetic Operator.

/* C Program to Calculate Square of a Number */
 
#include<stdio.h>
 
int main()
{
  int number, Square;
 
  printf(" \n Please Enter any integer Value : ");
  scanf("%d", &number);
  
  Square = number * number;
  
  printf("\n Square of a given number %d is  =  %d", number, Square);
 
  return 0;
}
C Program to Calculate Square of a Number 1

Program to Calculate Square of a Number using Functions

This C program to calculate square in allows the user to enter an integer value. And then, it finds the square of that number using Functions.

From the below C Programming code snippet, you can see we are using the Calculate_Square function. When the compiler reaches to Calculate_Square(number) line in main() program, the compiler will immediately jump to int Calculate_Square (int Number) function.

Calculate_Square (int Number) function will calculate the square and return the value.

/* C Program to Calculate Square of a Number using Function */
 
#include<stdio.h>

int Calculte_Square(int Number);
 
int main()
{
  int number, Square;
 
  printf(" \n Please Enter any integer Value : ");
  scanf("%d", &number);
  
  Square = Calculte_Square(number);
  
  printf("\n Square of a given number %d  =  %d", number, Square); 
 
  return 0;
}

int Calculte_Square(int Number)
{
	return Number * Number;
}
 Please Enter any integer Value : 9

 Square of a given number 9  =  81

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.