C++ Program:

- To print sideway triangle pattern using numbers

Example:

User Input: 3

Output:

A
A B
A B C
A B
A
#include <iostream>
using namespace std;

int main() {
  int columns,trows,k=1;
  char c;
  cout<<"Enter number of columns: ";
  cin>>columns;
  trows=2*columns-1;
  for(int i=1; i<=trows; i++) {
    c='A';
    for(int j=1; j<=k; j++) {
      cout<<c++<<" ";
    }
    if(i<columns)k++;
    else k--;
    cout<<endl;
  }
  return 0;
}

Output:

Enter number of columns: 4

A
A B
A B C
A B C D
A B C
A B
A
Program
pattern

Main Logic :

trows=2*columns-1;   // trows : total rows to print
k=1;  // Used to trigger decreasing order of alphabet

for(int i=1; i<=trows; i++) {
  c='A';
  for(int j=1; j<=k; j++) {
    cout<<c++<<" ";
  }
  //check for position change at which triangle alphabet value to decrease
  if(i<columns)k++;
  else k--;

  cout<<endl;
}

You can print the same pattern in small alphabets, just set c='a'

Concept

Coming Soon !

Quick
Tutorial

Quote

Make bold choices and make mistakes. It’s all those things that add up to the person you become.