Pages

Monday, February 15, 2021

C program to find square of given number without an argument and a return value

C Programming => Functions

C program to find square of given number using function concept. This program demonstrate use of function without an argument and a return value.

Program code

#include<stdio.h>
int square(); //function prototype declaration.
int number; //use of global variable

int main()
{
  int answer;
  answer = square(); //Call function.
  printf("Square of %d is %d.", number, answer);
  return 0;
}

//User defined function to find square()
int square()
{
  printf("Enter your number:");
  scanf("%d", &number);
  //return answer to main function
  return(number*number);
}

Output of the program

Enter your number:5
Square of 5 is 25.





No comments:

Post a Comment