0
How would I do this while using 2 nested loops beginner c++
1 2 3 4 5
2 ответов
+ 2
outer loop: loop it 5 times
int i=0; i<5; i++
inner loop:
int j=0; j<i; j++
(wont loop first time)
print a space inside inner loop
cout<<“ “;
exit to outter loop:
print i + 1 and go to next line
cout<< i + 1<<endl;
or👇🏾👇🏾👇🏾
#include <iostream>
using namespace std;
int main() {
for(int i=1; i <= 5;i++){
for(int j=1;j<i;j++){
cout<<" ";
}
cout<<i<<"\n";
}
return 0;
}
- 1
You don't need loops, just 5 times cout. Or one multiline string