Finding square root of a number without using Math.Sqrt Method in C Program
You may also like:
Calculate Square Root Without Using Math.Sqrt in C#
Calculate Square Root Without Using Sqrt in C
First one, we have to know how to calculate square root without using a function. For calculate square root of a number, we will use The Babylonian Method for Computing Square Roots
Here is source code of the C Program to Calculate Square Root Without Using Sqrt in C:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include<stdio.h> int main() { int number; double root = 1; int i = 0; printf("Enter a Number : "); scanf("%d",&number); while (1) { i = i + 1; root = (number / root + root) / 2; if (i == number + 1) { break; } } printf("%.2f",root); } |
Output: