Search This Blog

Monday, 29 April 2019

C Program to Calculate square of a number using functions

C Program to Calculate square of a number using functions 

This program to calculate square in c allows the user to enter an integer value and then finds the square of that number using Functions.

From the below 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.



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.



No comments:

Post a Comment