#include <stdio.h>
#include <math.h>
#include <stdlib.h> // For atof

typedef struct { double re, im; } complex;

complex init(double x, double y) { complex t;
   t.re = x; t.im = y;
   return t;
}

double modulus(complex a) {
  return sqrt(a.re * a.re + a.im * a.im);
}

complex add(complex a, complex b) { complex t;
   t.re = a.re + b.re;
   t.im = a.im + b.im;
   return t;
}

complex mult(complex a, complex b) { complex t;
   t.re = a.re * b.re - a.im * b.im;
   t.im = a.re * b.im + a.im * b.re;
   return t;
}

#define MAXIT 255
unsigned char mand(complex c) {
    register unsigned char i=1;
    complex z = c;
    do { z = add(mult(z,z), c); i++; } while ( modulus(z) <= 2.0 && i < MAXIT );
    return i;
}

int main (int argc, char *argv[])
{
  double x, y;

// Testing parameters and open output file
  if (argc != 3)
    {
      printf ("\nUSAGE: %s <real_part> <imaginary_part>\n\n", argv[0]);
      return 1;
    }
    
    x = atof (argv[1]);
    y = atof (argv[2]);
    unsigned char niter = mand(init(x,y));
    printf("%lf %lf %u\n", x, y, niter);
    printf("%lf %lf %u\n", x, -y, niter);
}
