[SOLVED] Little confusion on while/ do while loop in C. | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

[SOLVED] Little confusion on while/ do while loop in C.

Here in my code, I tried to place the increment operator inside printf() to reduce the lines of code by removing the { braces. int i = 201; while(i <= 300) printf("%d\t", i, i++); And. i = 201; do printf("%d\t", i, i++); while(i <= 300); Is this a valid way to do and how does this work?

6th Nov 2020, 3:18 AM
Bibek Oli
Bibek Oli - avatar
2 Respostas
+ 7
Try this printf("%d\t",i++); it will print current value and increment as your need
6th Nov 2020, 3:56 AM
Azhagesanćƒ¾(āœæ)
Azhagesanćƒ¾(āœæ) - avatar
+ 9
Why don't you try it on your own on code playground to see wether it is valid or notšŸ‘‡ https://code.sololearn.com/cfIc95OkbhvM/?ref=app { Warnings are generated because you are passing more than required arguments to printf() frunction. To get rid of that use method suggested by Azhagesanćƒ¾(Ė™ā„Ė™) }
6th Nov 2020, 3:57 AM
Arsenic
Arsenic - avatar