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
- #include <stdio.h>
- int square(int); // function prototype declaration.
- void main()
- {
- int number, answer;
- printf("Enter your number:");
- scanf("%d", &number);
- answer = square(number); //Call function.
- printf("Square of %d is %d.", number, answer);
- }
- int square(int n)
- {
- //function logic is written here..
- return(n*n); //This will return answer to main function.
- }
Output
Enter your number:5
Square of 5 is 25
Comments