Commit 5206735d by Andrew Dahl

Solved Problem 9

parent b815758e
Showing with 39 additions and 0 deletions
Question:
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a^2 + b^2 = c^2
For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
Answer: 31875000
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int c = 1;
for(int a = 1; a < 1000; a++)
{
for(int b = 1; b < 500; b++)
{
c = sqrt((a*a) + (b*b));
if((a + b + c) == 1000)
{
double temp = sqrt((a*a) + (b*b));
temp -= c;
if(temp == 0.0)
{
cout << (a*b*c) << endl;
return 0;
}
}
}
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment