C Program to find the square root of the given number without a square-root function

In this program we will going to find the square root of the given number without a square-root function.

C Program to find the square root of the given number without a square-root function

#include <stdio.h>
#include <conio.h>
int main()
{
  int num;
  float sqrt, s;
  printf(" Enter a number to get the square root: ");
  scanf(" %d", &num);
  sqrt = num / 2;
  s = 0;
  while (sqrt != s)
  {
    s = sqrt;
    sqrt = (num / s + s) / 2;
  }
  printf(" \n The square root of %d is %f", num, sqrt);
  return 0;
}

Output

Enter a number to get the square root: 2
The square root of 2 is 1.414214

Read: C Program To Convert Hexadecimal To Decimal


If You Like This Page Then Make Sure To Follow Us on Facebook, G News and Subscribe Our YouTube Channel. We will provide you updates daily.
Shares
facebook sharing button Share
twitter sharing button Tweet
whatsapp sharing button Share
telegram sharing button Share
pinterest sharing button Pin

Leave a Comment