- To print half triangle pattern using number
User Input: 3
Output:
1 2 2 3 3 3
#include <iostream>
using namespace std;
int main() {
int rows;
cout<<"Enter number of rows : ";
cin>>rows;
for(int i=1; i<=rows; i++) {
for(int j=1; j<=i; j++) {
cout<<i<<" ";
}
cout<<endl;
}
return 0;
}
Enter number of rows : 4 1 2 2 3 3 3 4 4 4 4Program
Main logic :
for(int i=1; i<=rows; i++) { //rows : number of rows to print
for(int j=1; j<=i; j++) {
cout<<i<<" ";
}
cout<<endl;
}
Concept
Coming Soon !
QuickStrength does not come from winning. Your struggles develop your strengths.