/* lp04.c -- lattice point triangle with integer sides by Michael Somos */ /* use "gcc -o lp04 lp04.c" to compile program */ /* Sun, Sep 8, 1997 Cleveland State University */ /* Wed, Aug 22, 2007 fix subtle bug in fsqrt() for(;;) sequencing code */ /* This program steps through all triangles with integer sides and selects those with integer areas and no common side factor. Call these "reduced Heronian triangles". Prints out an analysis of the integers constructed from the side lengths. */ #include #define AMAX 300 /*------ simple subroutines --------*/ /* sq2(x,y) = x*x + y*y */ int sq2(int x,int y) { return x*x+y*y ; } /* max(x,y) = maximum of x and y integers */ int max(int x,int y) { return (x>y)?x:y ; } /* isqrt(x) = floor(sqrt(x)) where x>0 is an integer */ int isqrt(int x) { int y,t; for(y=(1+x)/2;t=(y+x/y)/2,t0 is a double */ double fsqrt(double x) {double y,t;for(y=(1+x)/2;t=(y+x/y)/2,t m2*n3) at=1; else if (n3*m1 > m3*n1) at=2; else at=3; x1 = E1*(m1*m1-n1*n1) ; y1 = E1*(2*m1*n1) ; if (at==1) {x1=-x1;y1=-y1;} x2 = E2*(m2*m2-n2*n2) ; y2 = E2*(2*m2*n2) ; if (at==2) {x2=-x2;y2=-y2;} x3 = E3*(m3*m3-n3*n3) ; y3 = E3*(2*m3*n3) ; if (at==3) {x3=-x3;y3=-y3;} if (x3>=0 && x2<0) { X1=0 ; X2=x3 ; X3=-x2 ; } if (y3>=0 && y2<0) { Y1=0 ; Y2=y3 ; Y3=-y2 ; } if (x1>=0 && x3<0) { X1=-x3 ; X2=0 ; X3=x1 ; } if (y1>=0 && y3<0) { Y1=-y3 ; Y2=0 ; Y3=y1 ; } if (x2>=0 && x1<0) { X1=x2 ; X2=-x1 ; X3=0 ; } if (y2>=0 && y1<0) { Y1=y2 ; Y2=-y1 ; Y3=0 ; } Mx = max ( X1 , max ( X2 , X3 ) ) ; My = max ( Y1 , max ( Y2 , Y3 ) ) ; printf("%3d %3d %3d %3d",n,a1,a2,a3); printf(" : %3d %5d",2*s0,D); printf(" : %3d %3d %3d %3d %3d %3d",X1,Y1,X2,Y2,X3,Y3); /* printf(" : %3d %3d %3d %3d %3d %3d",p1,q1,p2,q2,p3,q3); */ printf(" : %2d %2d %2d %2d %2d %2d",n1,m1,n2,m2,n3,m3); printf(" : %d",at); printf("\n"); } /* end if d*d==dd */ } /* end gcd = 1 */ return 0; } /* end main */