Function square of number in C programming

By | June 21, 2019

“Function square of number in C programming” is a C language program to use a function to calculate square of given number. The square( ) will return square of the given number.

Function square of number in C programming

Function square of number in C programming

/*
Write a C program to use a function square()
that receives one number and returns its square
*/
int square(int a); /*function prototype or declaration*/
#include<stdio.h>
int main()
{
   int num1, result;
   /* Enter one number in main() */
   printf("Enter a number =");
   scanf("%d", &num1);
   /* call the function by sending one number */
   result = square(num1);
   printf("\n Square of %d = %d", num1,result);
   return 0;  
}
/* wrtite down function definition */
int square(int a)
{
	int s;
	s = a * a;
	return s;
}

Loading

Leave a Reply

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