- To print sideway reverse triangle pattern using *
User Input: 3
Output:
* * * * * * * * *
#include <iostream>
using namespace std;
int main() {
int columns,trows,k;
cout<<"Enter number of columns: ";
cin>>columns;
trows=2*columns-1;
k=trows;
for(int i=trows; i>=1; i--) {
for(int j=1; j<=trows; j++) {
if(j<k)cout<<" ";
else cout<<"* ";
}
if(i<=columns)k++;
else k--;
cout<<endl;
}
return 0;
}
Enter number of columns: 4 * * * * * * * * * * * * * * * *Program
Main Logic :
trows=2*columns-1; // trows : total rows to print
k=trows; // Used to trigger decreasing order of *
for(int i=trows; i>=1; i--) {
for(int j=1; j<=trows; j++) {
if(j<k)cout<<" ";
else cout<<"* ";
}
//check for position change at which triangle * value to decrease
if(i<=columns)k++;
else k--;
cout<<endl;
}
You can print any thing in this pattern, just replace your value with *
Coming Soon !
QuickThe dreams I chased took me on a journey, a journey more rewarding than the goals