#include <stdio.h>
#define MAX 1000
 
int main() {
    int i, j, k, maxP;
    int ps[1001];

    for(i = 1; i <= MAX; i++) {
        for(j = i;j <= MAX; j++) {
            for(k = j; (k * k) < (i * i + j * j); k++);
            if((i * i + j * j) == (k * k) && (i + j + k) <= MAX) {
                ps[i+j+k]++;
            }
        }
    }

    for(i = 1; i <= MAX; i++) {    
        if(ps[maxP] < ps[i])
            maxP = i;
    }

    printf("%d\n",maxP);

    return 0;
}

#include <stdio.h>
#define MAX 1000

int main() {
    int i, j , k, maxP = 1;
    int ps[1001];

    for (i=0; i <= MAX; ps[++i] =0);

    for(i = 1; i <= MAX; i++) {
        for(j = i;j <= MAX; j++) {
            for(k = j; (k * k) < (i * i + j * j); k++);
            if((i * i + j * j) == (k * k) && (i + j + k) <= MAX) {
                ps[i+j+k] += 1;
            }
        }
    }

    for(i = 1; i <= MAX; i++) {
        if(ps[maxP] < ps[i])
            maxP = i;
    }

    printf("%d\n",maxP);

    return 0;
}

Fix C solution for Problem039
Fix C solution for Problem039

The Author forgot to explicitily initialize the vector elements with
zeros. On my computer, without this, I get the wrong answer.

BTW, if maxP is not defined before, I don't even get a wrong answer.
A beatiful segmentation fault is raised.
