fork(1) download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. void out(int* a, int N, int w = 5)
  8. {
  9. int m = ceil((sqrt(1+8*N)-1)/2);
  10. for(int n = 0, row = 1;n < N;++row)
  11. {
  12. for(int i = 0; i < (m-row)*w/2; ++i) cout << " ";
  13. for(int i = 0; i < row && n < N; ++i) cout << setw(w) << left << a[n++];
  14. cout << endl;
  15. }
  16. }
  17.  
  18. int main(int argc, char * argv[])
  19. {
  20. int a[70];
  21. for(int i = 0; i < 70; ++i) a[i] = rand()%100;
  22. out(a,70);
  23. }
  24.  
Success #stdin #stdout 0s 5676KB
stdin
Standard input is empty
stdout
                           83   
                         86   77   
                      15   93   35   
                    86   92   49   21   
                 62   27   90   59   63   
               26   40   26   72   36   11   
            68   67   29   82   30   62   23   
          67   35   29   2    22   58   69   67   
       93   56   11   42   29   73   21   19   84   
     37   98   24   15   70   13   26   91   80   56   
  73   62   70   96   81   5    25   84   27   36   5    
46   29   13   57