0

How would I do this while using 2 nested loops beginner c++

1 2 3 4 5

5th Nov 2020, 10:30 PM
boba
boba - avatar
2 Antworten
+ 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; }
5th Nov 2020, 11:21 PM
Roderick Davis
Roderick Davis - avatar
- 1
You don't need loops, just 5 times cout. Or one multiline string
5th Nov 2020, 11:22 PM
Benjamin Jürgens
Benjamin Jürgens - avatar