fork download
  1. //Printing half pyramid using numbers
  2.  
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5.  
  6. int main(){
  7.  
  8. int rows;
  9. // Getting the number of rows.
  10. cout << "Enter the Number of rows - ";
  11. cin >> rows;
  12.  
  13. cout << "Triangle of " << rows << " using integers -\n";
  14.  
  15. // Main logic to print triangle.
  16. for( int i = 0; i < rows; i++ ) {
  17. for( int j = 0; j <= i; j++ ){
  18. cout << i + 1 << " ";
  19. }
  20. cout<<endl;
  21. }
  22.  
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0.01s 5300KB
stdin
6
stdout
Enter the Number of rows - Triangle of 6 using integers -
1 
2 2 
3 3 3 
4 4 4 4 
5 5 5 5 5 
6 6 6 6 6 6