Write a C program to find the square root of a given number. Note: Don’t use library function sqrt() and pow()
Write a C program to find the square root of a given number. Note: Don’t use library function sqrt() and pow()
#include<stdio.h>
void main()
{
int i;
float n, x;
printf("Enter a number\n");
scanf("%f",&n);
x=n;
if(n<0)
{
printf("The square root is not possible\n");
}
else
{
for(i=0;i<10;i++) // Newton Raphson Method
{
x=(x*x+n)/(2*x);
}
printf("The square root is %f\n", x);
}
}
Comments
Post a Comment