tags:

views:

114

answers:

3

How can I show the following pattern?

1 2 3 4 5
  1 2 3 4
    1 2 3
      1 2
        1
A: 

#include <iostream>

void pattern(const int N) {
for (int i=N;i>0;i--) {
for (int j=i;j std::cout << " ";
for (int j=0;j std::cout << j+1 << " ";
std::cout << std::endl;
}
}

int main(void){
pattern(5);
return 0;
}

JImmy Rigin
Nothing wrong with homework questions.
Martin York
Complete solution provided.
JImmy Rigin
+4  A: 

This should do the trick:

cout << "1 2 3 4 5" << "\n";
cout << "  1 2 3 4" << "\n";
cout << "    1 2 3" << "\n";
cout << "      1 2" << "\n";
cout << "        1" << endl;
NullUserException
+2  A: 

printf("1 2 3 4 5\n  1 2 3 4\n    1 2 3\n      1 2\n        1\n");

That'll be four peanuts please.

corlettk
Thats the C way. Ahhh clever... trying to trick him ehh?
thyrgle