You are here:

- Home
- Computing/Technology
- C/C++
- C++
- Sorry... =)

Advertisement

Hello Sandra. I will show to you my work in C++ maybe later... for now, I was wrong in asking the syntax for the inverted triangle output.. =) It worked anyway... =) The output for the program must looked like this: Imagine the head of an arrow pointing down and then discard the tail. That must be the triangle that I was mistaken for. =) The output can also be imagined as a closed letter "V". I hope I have interpreted it correctly for you.. =)

Well, if you could use a loop it would make things easier. But as it is the best way would be to add another recursive function to print spaces before calling col. You can then use the base_size - size trick to calculate how many spaces to print:

#include <iostream>

using namespace std;

int col ( int seed, int size )

{

if ( size == 0 ) {

cout<<'\n';

return seed;

}

cout<< seed <<' ';

return col ( ( seed + 1 == 10 ) ? 0 : seed + 1, size - 1 );

}

void space ( int n )

{

if ( n == 0 )

return;

cout<<' ';

space ( n - 1 );

}

void print ( int seed, int size )

{

static int base_size = size;

if ( size == 0 )

return;

space ( base_size - size );

print ( col ( seed, size ), size - 1 );

}

int main()

{

print ( 4, 5 );

}

- Add to this Answer
- Ask a Question

Rating(1-10) | Knowledgeability = 10 | Clarity of Response = 10 | Politeness = 10 |

Comment | Your example is easy to understand, thanks |

I can help with any questions concerning ISO standard C++, object oriented programming and design as well as algorithms and data structures.

I have nine years of programming experience with C++.