fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int totalnos, j, i;
  7. int numPos = 0;
  8.  
  9. cout << "Enter total numbers: ";
  10. cin >> totalnos;
  11.  
  12. int numbers[totalnos];
  13.  
  14. cout << "Enter the numbers: ";
  15. for (i = 0; i < totalnos; i++)
  16. {
  17. cin >> numbers[i];
  18. }
  19.  
  20.  
  21. cout << endl;
  22. for (i = 0; i < totalnos; i++)
  23. {
  24. if ( ( totalnos - i ) < numPos ) {
  25. numPos = totalnos - i;
  26. }
  27.  
  28. for (j = 0; j < i; j++)
  29. {
  30. cout << numbers[numPos] << ' ';
  31. ++numPos;
  32. }
  33. cout << endl;
  34. }
  35. }
Success #stdin #stdout 0s 3460KB
stdin
5
3
8
2
4
9
stdout
Enter total numbers: Enter the numbers: 

3 
8 2 
2 4 9 
8 2 4 9