ChanTico
January 2nd, 2009, 05:38 AM
Hi, I'm trying to write to a program where the intergers 1-10 are placed in a triangle such that the number above is equal to the difference of the two below.
Which is basically the same as putting the number 1-10, in any order and trying every combinaion. Is there a better way than using 10 loops?
I wrote the program and just got a flashing cursor, for a long time. Editing the code, I got this,
int num [1], n(0); //My intergers
while (n<2)
{
num [n] =1; n++;
}
while (num[1] <11)
{
while (num [0] <11)
{
cout << num [1] << num [0];
num [0]++;
}
num [0]=1; num[1]++;
}
Which prints, all number 11 through 99, excluding any with zeros.
But.
int num [2], n(0); //My intergers
while (n<3)
{
num [n] =1; n++;
}
while (num [2] <11)
{
while (num[1] <11)
{
while (num [0] <11)
{
cout << num [1] << num [0];
num [0]++;
}
num [0]=1; num[1]++;
}
num [0] =1; num [1]=1; num [2]++;
}
Appears to just crash, I only see a cursor flickering. I tried google and people seem to think that triple loops work fine. Is there anything obviously wrong?
Which is basically the same as putting the number 1-10, in any order and trying every combinaion. Is there a better way than using 10 loops?
I wrote the program and just got a flashing cursor, for a long time. Editing the code, I got this,
int num [1], n(0); //My intergers
while (n<2)
{
num [n] =1; n++;
}
while (num[1] <11)
{
while (num [0] <11)
{
cout << num [1] << num [0];
num [0]++;
}
num [0]=1; num[1]++;
}
Which prints, all number 11 through 99, excluding any with zeros.
But.
int num [2], n(0); //My intergers
while (n<3)
{
num [n] =1; n++;
}
while (num [2] <11)
{
while (num[1] <11)
{
while (num [0] <11)
{
cout << num [1] << num [0];
num [0]++;
}
num [0]=1; num[1]++;
}
num [0] =1; num [1]=1; num [2]++;
}
Appears to just crash, I only see a cursor flickering. I tried google and people seem to think that triple loops work fine. Is there anything obviously wrong?