Skip to content

Commit 23286bc

Browse files
committed
Generate all Pythagorean Triplets upto Limit
1 parent 699e598 commit 23286bc

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

generate_pythagorean_triplet.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <iostream>
2+
using namespace std;
3+
void genPythagoreanTriplets(int l)
4+
{
5+
int a, b, c = 0;
6+
int m=2;
7+
while (c < l)
8+
{
9+
for(int n=1; n<m; ++n)
10+
{
11+
a = m*m-n*n;
12+
b = 2*m*n;
13+
c = m*m+n*n;
14+
if(c > l)
15+
break;
16+
cout<<"("<<a<<", "<<b<<", "<<c<<")\n";
17+
}
18+
m++;
19+
}
20+
}
21+
22+
int main()
23+
{
24+
int l;
25+
cout<<"Enter the limit: ";
26+
cin>>l;
27+
cout<<"The various generated Pythagorean Triplets are:\n";
28+
genPythagoreanTriplets(l);
29+
return 0;
30+
}

0 commit comments

Comments
 (0)