Algorithms_in_C  1.0.0
Set of algorithms implemented in C.
sol2.c File Reference

Problem 9 solution More...

#include <stdio.h>
#include <stdlib.h>
Include dependency graph for sol2.c:

Functions

int main (void)
 Main function.
 

Detailed Description

Problem 9 solution

Author
Krishna Vedala

Problem Statement: 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.

Given \(a^2 + b^2 = c^2\) and \(a+b+c = n\), we can write:

\begin{eqnarray*} b &=& \frac{n^2 - 2an}{2n - 2a}\\ c &=& n - a - b \end{eqnarray*}