- To print half triangle pattern using alphabet
User Input: 3
Output:
A A B A B C
#include <iostream>
using namespace std;
int main() {
int rows;
char c;
cout<<"Enter number of rows : ";
cin>>rows;
for(int i=1; i<=rows; i++) {
c='A';
for(int j=1; j<=i; j++) {
cout<<c++<<" ";
}
cout<<endl;
}
return 0;
}
Enter number of rows : 4 A A B A B C A B C DProgram
Main logic :
for(int i=1; i<=rows; i++) { //rows : number of rows to print
c='A';
for(int j=1; j<=i; j++) {
cout<<c++<<" ";
}
cout<<endl;
}
You can print the same pattern in small alphabets, just set c='a'
Coming Soon !
QuickThe dreams I chased took me on a journey, a journey more rewarding than the goals