glendaProblem 94549a2918 years agoHistory
41 lines · 615 B · C
RawDownload
#include <u.h>#include <libc.h> /*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.cThere exists exactly one Pythagorean triplet for whicha + b + c = 1000.  Find the product abc. */ voidmain(){	int product;	int a;	int b;	int c; 	for(int m = 0; m < 100; m++){		for(int n = 0; n < 100; n++){			// Euclid's formula			a = pow(m, 2) - pow(n, 2);			b = 2 * m * n;			c = pow(m, 2) + pow(n, 2); 			if (a + b + c == 1000){				product = a * b * c;			}		}	} 	print("Product: %d\n", product);	exits(0);}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t