C program to find square of given number using function. Use of function with an argument and a return value

C program to find square of given number using function. Use of function with an argument and a return value

  1. #include <stdio.h>
  2. int square(int); // function prototype declaration.
  3. void main()
  4. {
  5.      int number, answer;
  6.      printf("Enter your number:");
  7.           scanf("%d", &number);
  8.      answer = square(number); //Call function.
  9.      printf("Square of %d is %d.", number, answer);
  10.      }
  11. int square(int n)
  12. {
  13.      //function logic is written here..
  14.           return(n*n); //This will return answer to main function.
  15.           } 

Output
Enter your number:5
Square of 5 is 25

choose next program from this list

Comments