fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int rows;
  6. // Getting the number of rows.
  7. cout << "Enter the Number of rows - \n";
  8. cin >> rows;
  9.  
  10. cout << "Triangle of " << rows << " using * -\n";
  11.  
  12. // Main logic to print triangle.
  13. for( int i = 0; i < rows; i++ ) {
  14. for( int j = 0; j <= i; j++ ){
  15. cout << "* ";
  16. }
  17. cout<<endl;
  18. }
  19.  
  20. cout << "Triangle of " << rows << " using integers -\n";
  21.  
  22. // Main logic to print triangle.
  23. for( int i = 0; i < rows; i++ ) {
  24. for( int j = 0; j <= i; j++ ){
  25. cout << i + 1 << " ";
  26. }
  27. cout<<endl;
  28. }
  29.  
  30. cout << "Triangle of " << rows << " using characters -\n";
  31.  
  32. // Main logic to print triangle.
  33. for( int i = 0; i < rows; i++ ) {
  34. for( int j = 0; j <= i; j++ ){
  35. cout << (char)('A' + j) << " ";
  36. }
  37. cout<<endl;
  38. }
  39.  
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5300KB
stdin
6
stdout
Enter the Number of rows - 
Triangle of 6 using * -
*  
*  *  
*  *  *  
*  *  *  *  
*  *  *  *  *  
*  *  *  *  *  *  
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 
Triangle of 6 using characters -
A 
A B 
A B C 
A B C D 
A B C D E 
A B C D E F