COMP2113
COMP2113_ENGG1340 Programming technologies and Computer programming II [Section 2BC] [2023]
Loading...
Searching...
No Matches
Functions
3alt.cpp File Reference
#include <iostream>
Include dependency graph for 3alt.cpp:
Go to the source code of this file.
Functions
int
main
()
Function Documentation
◆
main()
int main
(
void
)
Definition at line
4
of file
3alt.cpp
.
4
{
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
}
moretest.a
a
Definition
moretest.py:10
Assignment1
3alt.cpp
Generated on Sun Sep 29 2024 16:39:53 for COMP2113 by
1.12.0