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