0

how to print a number from 10 to 1. Using do while loop. But The Initial value shoudl be 1

11th Nov 2017, 4:26 PM
Abdul Wahab
Abdul Wahab - avatar
6 Respuestas
+ 2
1) I understood your first original post correctly 2) You mentioned to me that it was the reverse order, okay, so I gave you an edited code with the very minor changes. 3) You now say that I didn't understand, and that you now need to print it to the screen a specific way and hope that I "get it". I'm sorry but, I've supplied you with all the code needed plus even made the minor changes. I'm here to help you, not write all your code for you. The change you're asking for is so easy to do, you delete one special pair of characters. I'll let you figure it out. Part of being a programmer is being able to be independent and resourceful.
11th Nov 2017, 4:59 PM
Sapphire
+ 1
If the initial value starts at 1, and ends at 10: #include<stdio.h> int main() { int counter = 1; do{ printf("%i\n", counter); } while(++counter < 10); return 0; } The while loop after 'do' acts as a break, and also increases the value of counter in the process BEFORE checking its condition. This is important because if you increment after, the end value will be 11 (condition is checked before value is increased).
11th Nov 2017, 4:38 PM
Sapphire
+ 1
It's not that difficult. You just change counter to start at 10, and tell the while loop to decrease the value and flip the operator: #include<stdio.h> int main() { int counter = 10; do{ printf("%i\n", counter); } while(--counter > 0); return 0; }
11th Nov 2017, 4:42 PM
Sapphire
0
but the initial value must start from 10 and ends on 1
11th Nov 2017, 4:40 PM
Abdul Wahab
Abdul Wahab - avatar
0
hahaha Sir You. didn't get it my point I mean to say that we gave the initial value 1 and ends value 10 and use negative decrement operator. and the result should be print like this 10 9 8 7 6 5 4 3 2 1;.. hope you will. get it ...😃😉
11th Nov 2017, 4:46 PM
Abdul Wahab
Abdul Wahab - avatar
0
yeah Thanks Man And sorry if u mind it ,😓😓😓😢😢😢😢😩😩
11th Nov 2017, 5:01 PM
Abdul Wahab
Abdul Wahab - avatar