/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
int main()
{
const int imax=10000;
float xinv=1;
const float eps=0.001; //three digits
float x=0.1; //numero di cui calcolare l'inverso
for (int n=0;n<imax;n++)
{
if ((x*xinv)<1) xinv+= eps/(x*xinv);
else xinv-=eps*(x*xinv);
}
printf("x=%f 1/x=%f err=%f",x,xinv,x*xinv);
return 0;
}