Thursday, July 26, 2012

C Program to Calculate Square Root Of a Number

#include<stdio.h>
#include<conio.h>
float sqroot(float );
void main()
{
    float n,a;
    scanf("%f",&n)
    a=sqroot(n);
    getch();
}
    float sqroot(float m)
{
      float i=0;
    float x1,x2;
    while( (i*i) <= m )
             i+=0.1;
    x1=i;
    for(int j=0;j<10;j++)
    {
          x2=m;
        x2/=x1;
        x2+=x1;
        x2/=2;
        x1=x2;
    }
    return x2;
}

No comments:

Post a Comment