954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C++ Pythagorean Triple

my question is how can i make my program not to display any unique combination more that ones?

//*****f04.cpp*****
//Name:
//Date: 02 - 17 - 08

#include
using namespace std;

int main ()
{
// #1
int a, b, c;
for (c = 1; c *c <= 100; c++)
{
for (a = 1; a <= 100; a++)
{
for (b = 1; b <= 100; b++)
{
if (c * c == a * a + b * b)
cout << c << ", " << a << " and " << b << endl;
}
}

}

Dr_Pepper
Newbie Poster
6 posts since Feb 2008
Reputation Points: 10
Solved Threads: 1
 

How about for (b = 1; b <= a; b++) ?

vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
 

Thanks alot! I didn't think that fix would be that easy.

Dr_Pepper
Newbie Poster
6 posts since Feb 2008
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You