COMP2113
COMP2113_ENGG1340 Programming technologies and Computer programming II [Section 2BC] [2023]
Loading...
Searching...
No Matches
3alt.cpp
Go to the documentation of this file.
1
#include <iostream>
2
using namespace
std;
3
4
int
main
(){
5
unsigned
long
long
int
p,a,b,c;
6
cin >> p;
7
for
(a=1;a<p/2;a++){
8
//given a*a+b*b=c*c a+b+c=p
9
//we can express b in terms of p and a
10
//since we have 4 unknown variables and 2 equations
11
b = p * (p - 2 * a) / (2 * (p - a));
12
c = p - a - b;
13
//check to ensure
14
if
((a*a+b*b==c*c) && (a<b) && (b<c)) {
15
cout << a <<
" "
<< b <<
" "
<< c <<
"\n"
;
16
}
17
}
18
return
0;
19
}
main
int main()
Definition
3alt.cpp:4
Assignment1
3alt.cpp
Generated on Sun Sep 29 2024 16:39:53 for COMP2113 by
1.12.0