#include <stdio.h>

int Findnumberoftriples (int N) /*Creating a function to count the number of triples in the range*/
{
    int a, b, c, count=0;

        for (c=0; c<N; c++)
        {
            for (b=0; b<c; b++)
            {
                for (a=0; a<b; a++)
                {
                    if ( a*a+b*b==c*c)
                    count++;
                }
            }
        }
    return count;
}

int main()
{
    /*declaire and initialize variables*/
    int a, b, c, N, maxa, maxb, maxc, count;

    maxc=-999;

    /*Prompt user to enter a positive integer N*/

    printf("Please enter a positive integer\n");
    scanf("%d", &N);

    /*Use the Findnumberoftriples function to find the number of triples within this range, and assign this number to count.*/

    count=Findnumberoftriples(N);

    if (count>0)
        {
            printf("There are %d Pythagorean triples in this range\n", count);

            for (c=0; c<N; c++)
            {
                for (b=0; b<c; b++)
                {
                    for (a=0; a<b; a++)
                    {
                        if ( a*a+b*b==c*c)
                        {
                            printf("\t( %d, %d, %d)\n", a, b, c);

                            if ( maxc<c)
                                {
                                    maxa=a;
                                    maxb=b;
                                    maxc=c;
                                }
                        }
                    }
                }
            }

        printf("The Pythagorean triple with the largest c value is ( %d, %d, %d)", maxa, maxb, maxc);

        }

        else
        {
            printf("There are no Pythagorean triples in this range.\n");
        }
    return 0;
}
