4th Street Bar Hive-Bar

Hive-Bar Powered by Hive beta-fdb5b5b

Community post

C program to find square root of a number ( With Algorithm )

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 )


  1. Start
  2. Accept one number from user.
  3. Use the function sqrt() to find square root.
  4. Print the result.
  5. End

Program of square root in C


#include<stdio.h>
#include<conio.h>
#include<math.h>

int main()
{
int n,result;
printf("Enter any number :\t");
result=sqrt(n);
printf("\nSquare root of given number is : %d",result);
getch();
}

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.


132 upvotes $4.32

Replies (7)

Review before signing

Posting as . Signing with . Keychain permission: Posting. Hive Keychain will ask you to approve this action next.


  
Technical details

Operation fingerprint: