xxxxxxxxxx
#include <iostream>
using namespace std;
int main() {
// Define the number of rows
int num_rows = 4;
// Initialize start number
int start_num = 1;
// Loop for each row
for (int i = 0; i < num_rows; i++) {
// Set the current number to the start number
int current_num = start_num;
// Loop for each column in the row
for (int j = 0; j <= i; j++) {
// Print the current number followed by a space
cout << current_num << " ";
// Increment the current number
current_num++;
}
// Move to the next line after printing the row
cout << endl;
// Increment the start number for the next row
start_num++;
}
return 0;
}
xxxxxxxxxx
#include <iostream>
#include <iomanip>
using namespace std;
// operator overloading on * to print 's' 'n' no. of times just like in python
string operator*(string s, int n){
string result = "";
for(int i=0; i<n; i++){
result += s;
}
return result;
}
int main() {
int n;
string s = "*";
cin >> n;
for(int i=1; i<=n; i++)
cout << setw(n) << s*i << endl;
return 0;
}