Wednesday, December 28, 2011

Square Root without using sqrt

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

2 comments:

  1. int main()
    {
    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;
    }

    ReplyDelete
  2. Nishikanta Pradhan
    ----------------------------------

    #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();
    }

    ReplyDelete