Finding square root of any number is pretty simple. In this post, i will explain you step-by-step to find square root of any given number using a predefined function sqrt(). Before checking program, i will suggest you to clear your concept related to "What is square root & how to find them ?"
For better understanding of C program, please refer C program of addition of two numbers.
What is square root of any number ?
Square root of any number is just the reverse of squaring of that number. We already know that square of any number is the number multiplied by itself. i.e., if we suppose to find the square of any number say 3, then its square is 9.
Coming to square root,
Square root of any number (say) 81 is 9. Lets find it graphically.
Algorithm of program ( Square root in C )
- Accept one number from user.
- Use the function sqrt() to find square root.
- Print the result.
Program of square root in C
printf("Enter any number :\t");
printf("\nSquare root of given number is : %d",result);
Explanation of program of square root
- Declaration of Header File : Before writing any program, firstly we have to declare its Header files which we have to use in our program. If you are not familiar with header files then please refer Use of header file in C.
- Declaration of data types : For this program of square root, we need to declare two data types of int type i.e., one for taking input from user and other one for storing the result in it.
- Use of sqrt() function : Sqrt() function is a predefined function present in math.h library. The main purpose of using sqrt() function is, it will give the square root of any number using its predefined definition.