Explain the output of the given code taken from C++ challenges | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Explain the output of the given code taken from C++ challenges

for(int i = 0;i<=2;i++) { for(int j = 0; j <=i; j++){ cout << "*";} cout << "_"; }; This code give the output *_**_ Anyone Explain how this answer come }

25th Dec 2018, 4:42 PM
Saad Mughal
Saad Mughal - avatar
2 Answers
+ 4
Saad Mughal Actually your output is wrong and your code has many mistakes First iteration i=0 j=0 prints *_ Second iteration i=1 j=0 prints * i=1 j=1 prints *_ Third iteration i=2 j=0 prints * i=2 j=1 prints * i=2 j=2 prints *_ Overall output *_**_***_
25th Dec 2018, 4:58 PM
deeyae
deeyae - avatar
+ 1
Yeah i corrected my code but the code and answer is same as the challenge question but if it is incorrect I understand the way you explained there Thanks
25th Dec 2018, 5:07 PM
Saad Mughal
Saad Mughal - avatar