/*------------------------------------------------
Name: Sam Kajjo, student number: 7602089
Date: 11th oct 2015
Program: pythagorean triple
Discription: find the number of c
bewteen 0 and a psitive integer number,
the pythagorean triple, and the pythagorean triple
with highst value of last number in triple
-------------------------------------------------*/
#include <stdio.h>
#include<math.h>

int main()
{
/* declare and inialized the variables*/
int a, b,c, d, N, max;
max = 0;
printf("Enter an possitive integer:");
scanf("%d", &N);
/* find the number of the pythagorean in the range of 0 and N */
/* check the all values of a */
for (a=1; a < b ; a++)
{
     /* check the all values of b for a specific  value of b */
    for (b=2; ((a*a) + (b*b)) < (N*N) ; b++)
    {
        /* check the all values of c for a specific value of a and b */
        for (c=3; c<N && b>a ; c++ )
        {
            /*checking if the c value is c= square root of ((a*a)+(b*b))*/
            if (c== sqrt (((a*a)+(b*b))))
            {
                d=d+1;
            }
        }
    }
}
/*checking if there is a pythageren triple between 0 and N */
if (d == 0)
{printf("there is no pythagorean triple.\n");
}
else
{printf("there are %d pythagrean triple in this range:\n", d);
}
/* finding the pythagorean triples and print them*/
/* check the all values of a */
for (a=1; a < b ; a++)
{
     /* check the all values of b for a specific  value of b */
    for (b=2; ((a*a) + (b*b)) < (N*N) ; b++)
    {
        /* check the all values of c for a specific value of a and b */
        for (c=3; c<N && b>a ; c++ )
        {
            /*checking if the c value is c= square root of ((a*a)+(b*b))*/
            if (c== sqrt (((a*a)+(b*b))))
            {

                printf("(%d,%d,%d)\n", a,b,c);
               /* finding the highest value of c*/
               if (c > max)

                max = c;
            }

        }
    }
}
/*finding the pythagorean triple with the highest c value*/
/* check the all values of a */
for (a=1; a < b ; a++)
{
    /* check the all values of b for a specific  value of b */
    for (b=2; ((a*a) + (b*b)) < (N*N)   ; b++)
    {
        /* checking if max is the same than c as max square root of  ((a*a)+(b*b)) && a < b)*/
        if (max == sqrt ((a*a)+(b*b)) && a < b)
printf ("the triple wih the large value of c is (%d,%d,%d)\n", a,b,max);
    }
}
}


