fueanta

Triangle of integers

Sep 6th, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. // cpp program: triangle of integers
  2. // created on April, 2016
  3. // Author: fueanta
  4.  
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. int main(void) {
  9.     int x;
  10.     cout << "Give the number: ";
  11.     cin >> x;
  12.     int m=x,n=1;
  13.     for (int i=0;i<x;i++) {
  14.             m--;
  15.         for (int j=0;j<m;j++) {
  16.             cout << " ";
  17.         }
  18.         for (int k=0;k<x-m;k++) {
  19.             cout << n;
  20.             n++;
  21.         }
  22.         n-=2;
  23.         for (int l=0;l<x-m;l++) {
  24.             if (n>0) {
  25.                 cout << n;
  26.                 n--;
  27.             }
  28.         }
  29.         n=1;
  30.         cout << endl;
  31.     }
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment