#include <stdio.h>
#include <stdlib.h>

float f1(float x, float y);
float f1(float x, float y);
float max(float x, float y);

float f1(float x, float y)
{
  return(-x-y*y+1);
}

float f2(float x, float y)
{
  return(-x*x-y-1);
}

float max(float x, float y)
{
      float mayor;
      if(x>=y) mayor=fabs(x);
      else mayor=fabs(y);
      return mayor;
}
int main()
{
  FILE *salida;
  salida=fopen("e:/NR.txt","w");
  float a,b,c,d, ain, bin, cin, din;
  float x0,y0, v1, v2, h1, h2, x1, y1, error, eps, Det;
  int cont=1;
  printf("\nIngrese x0 : ");
  scanf("%f",&x0);
  printf("\nIngrese y0 : ");
  scanf("%f",&y0);
  printf("\nIngrese error : ");
  scanf("%f",&eps);
  fprintf(salida,"x0 : %0.9f\n",x0);
  fprintf(salida,"y0 : %0.9f\n",y0);
  fprintf(salida,"error : %0.9f\n",eps);
  do
  {
  fprintf(salida,"_______________________________________________\n");
  fprintf(salida,"\Iteracion %i\n",cont);
  a=1; b=2*y0 ; c=2*x0; d=1;
  Det=a*d-b*c;
  ain=1/Det*d;
  bin=-1/Det*b;
  cin=-1/Det*c;
  din=1/Det*a;
  v1=f1(x0,y0); v2=f2(x0,y0);
  h1=ain*v1+bin*v2;
  h2=cin*v1+din*v2;
  error=max(h1,h2);
  fprintf(salida,"\nh1 : %0.9f\n ",h1);
  fprintf(salida,"\nh2 : %0.9f\n ",h2);
  x1=h1+x0;
  y1=h2+y0;
  
  fprintf(salida,"\nx1 : %0.9f\n ",x1);
  fprintf(salida,"\ny1 : %0.9f\n ",y1);
  cont++;
  x0=x1; y0=y1;
   }
   while(error>=eps);
   fclose(salida);
  system("PAUSE");	
  return 0;
}
