/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * arctan.c
 * Copyright (C) drdev 2012 <gualtieri**AT**ieee.org>
 * 
 * arctan_Diophantine is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * arctan_Diophantine is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

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

/* Prototypes */
void exit(int status);
double atan( double arg );
double tan( double arg );
double round (double arg);
char *strcpy(char *dest, const char *src);
/* end of prototypes */

char fn1[64];
double total;
double tangent;
double close;
int i,j,k;
FILE *outdata;

int main(int argc, char *argv[])
{

strcpy(fn1,argv[1]);
printf("\nOutput file selected = %s\n",fn1);

if ((outdata = fopen(fn1,"w"))==NULL)
	{printf ("\nOutput file cannot be opened.\n");
	exit (1);}
	
printf("alpha\tbeta\tgamma\n");
fprintf(outdata,"alpha\tbeta\tgamma\n");
	
for (i=1;i<100;i++)
{
for (j=1;j<100;j++)
{

total=atan((1/(double)i))+atan((1/(double)j));

tangent = tan(total);
tangent = 1/tangent;

close = round(tangent) -(tangent);

if(close<0) close = -close;

if ((close<0.001))
{
printf("%d\t%d\t%f\n",i,j,tangent);
fprintf(outdata,"%d\t%d\t%f\n",i,j,tangent);
}


}
}

fclose(outdata);
printf("\nDone.\n");

return 0;

}
