Project Euler Problem 9

There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.

C Script

#include <stdio.h>

int main (int argc, const char * argv[]) {
	int a, b, c, n, m, sum, out;
	for(n = 1; n < 20; n++) {
		for(m = n+1; m < n + 21; m++) {
			a = m * m - n * n;
			b = 2 * m * n;
			c = m * m + n * n;
			sum = a + b + c;
			if(sum == 1000) {
				out = a * b * c;
			}
		}
	}
	printf("%d", out);
	return 0;
}

Leave a Reply

Your email address will not be published.