/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* heron.c
* Copyright (C) 2014 DM Gualtieri
*
* Heron 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.
*
* Heron 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 .
*/
// 24 January 2014
/*Finds triangles with integer sides and area using Heron's formula.
Reference: Sascha Kurz, Serdica Journal of Computing Vol. 2 (2008),
Pages 181-196; also at
*/
#include
#include
#define upper 500 //upper limit on side length
/* Prototypes */
char *strcpy(char *dest, const char *src);
/* end of prototypes */
long a_factor;
int i;
int a,b,c;
int s;
long squares[5*upper] = {0};
char fn[64];
FILE *outdata;
//Returns greatest common divisor of (x,y)
int gcd ( int x, int y )
{
int z;
while ( x != 0 )
{
z = x;
x = y%x;
y = z;
}
return y;
}
int main(int argc, char *argv[])
{
if(argc<2)
{
strcpy(fn,"output.txt");
}
else
{
strcpy(fn,argv[1]);
}
printf("\nOutput file selected = %s\n",fn);
if ((outdata = fopen(fn,"w"))==NULL)
{printf ("\nOutput file cannot be opened.\n");
exit (1);}
//Build table of squares
for(i=0;i<(5*upper);i++)
{
squares[i] = i*i;
}
for(a=1;a