Wednesday 25 September 2013

program to find the square root of a given number without using library function

    #include<stdio.h>
    float SquareRoot(float num);
    void main()
    {
    float input, ans;
  
    ans = SquareRoot(9);
    printf("\n Square Root : %f", ans);
  
    }
    float SquareRoot(float num)
    {
    if(num >= 0)
    {
    float x = num;
    int i;
    for(i = 0; i < 20; i ++)
    {
        x = (((x * x) + num) / (2 * x));
    }
    return x;
    }
    }



No comments:

Post a Comment