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

in programming •  9 days ago

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.


Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Hello! Your post has been resteemed and upvoted by @ilovecoding because we love coding! Keep up good work! Consider upvoting this comment to support the @ilovecoding and increase your future rewards! ^_^ Steem On!

Reply !stop to disable the comment. Thanks!

You gave us an unique information.I never thing that the square root also used in algorithms

Posted using Partiko Android

To listen to the audio version of this article click on the play image.

Brought to you by @tts. If you find it useful please consider upvoting this reply.

You got a 4.63% upvote from @postpromoter courtesy of @shivangi!

Want to promote your posts too? Check out the Steem Bot Tracker website for more info. If you would like to support the development of @postpromoter and the bot tracker please vote for @yabapmatt for witness!

well done

Congratulations @shivangi! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

Award for the total payout received

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Support SteemitBoard's project! Vote for its witness and get one more award!

Hehe thanks for posting it..!!
Your post took me back to first year C programming class
:-)