All pastes #762817 Raw Edit

Something

public text v1 · immutable
·published 2007-11-05 22:39 UTC
rendered paste body
#include <stdio.h>
#include <math.h>


float mySqrt(float a,int *interations);

int checkFloat(float x);



int checkFloat(float x)
{
   if(x<0)
   {
      return 0;
   }

   else
   {
      return 1;
   }
}



float mySqrt(float a,int *interations)
{
   int n=0,x=1,cnt=0;

   checkFloat(a);

   do{

      x=0.5*(x+(a/x));
      cnt++;
      x++;
      n++;
      }while((pow(x,n)-pow(x,n-1))<pow(10,-5));

   *interations=cnt;
   return x;
}



int main(void)
{

   float k;
   int *interations;

   scanf("%f",&k);

   printf("mySqrt =%f\n",mySqrt(k,*interations));
   printf("epanalipseis=%d\n",*interations);
   printf("sqrt=%f\n",sqrt(k));
   printf("pow=%f",pow(10,-5));

   return 0;
}