Find the square root of a number with out using square root function.
Also calculate square root of floating point number
http://en.wikipedia.org/wiki/Fast_inverse_square_root
Also calculate square root of floating point number
http://en.wikipedia.org/wiki/Fast_inverse_square_root
int main()
ReplyDelete{
float num;
float temp, temp1;
num = 2;
temp = num/2; temp1 = 0;
while( temp != temp1)
{
temp1 = temp;
temp = (num/temp + temp)/2;
}
printf ("square root of a number : %f\n", temp);
return 0;
}
Nishikanta Pradhan
ReplyDelete----------------------------------
#include
#include
void main()
{
float number;
float sqroot,temp;
clrscr();
printf("Enter a Number: ");
scanf("%f",&number);
sqroot=number/2;
temp=0;
while(sqroot!=temp)
{
temp=sqroot;
sqroot=(number/sqroot+sqroot)/2;
}
printf("Square root of %f is %f",number,sqroot);
getch();
}