fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int size = 3;
  6.  
  7. int tab[size][size] =
  8. {
  9. {0, 1, 2},
  10. {0, 1, 2},
  11. {0, 1, 2}
  12. };
  13. int main(int argc, char** argv)
  14. {
  15. int rows = (size*2)-1;
  16.  
  17. int x,y;
  18.  
  19. for(int i=0; i < rows; i++)
  20. {
  21. i >= size ? x = i+1 - size : x=0;
  22. i >= size ? y = size-1 : y=i;
  23.  
  24. do
  25. {
  26. cout << tab[x][y] << " ";
  27. x++; y--;
  28.  
  29. if( x > size-1 || y > size-1)
  30. break;
  31. }
  32. while(x < i+1);
  33. cout << endl;
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
0 
1 0 
2 1 0 
2 1 
2