- To print alphabet A pattern using *
User Input: 3
Output:
* * * * * *
#include <iostream>
using namespace std;
int main() {
int rows;
cout <<"Enter number of rows: ";
cin >> rows;
for(int i=rows; i>=1; i--) {
for(int j=1; j<=(2*rows-i); j++) {
if(j==i||j==(2*rows-i)||(j>i && i==rows/2+rows%2))cout<<"* ";
else cout<<" ";
}
cout<<endl;
}
return 0;
}
Enter number of rows: 5 * * * * * * * * * * * *Program
Main Logic :
for(int i=rows; i>=1; i--) {
for(int j=1; j<=(2*rows-i); j++) {
if(j==i||j==(2*rows-i)||(j>i && i==rows/2+rows%2))cout<<"* ";
else cout<<" ";
}
cout<<endl;
}
You can print any thing in this pattern, just replace your value with *
Coming Soon !
QuickIn order to succeed you must fail, so that you know what not to do the next time.