0

How to print this series Using One Loop.

Input 1 : 3 Output : 0 1 2 3 2 1 0 Input 2 : 5 Output : 0 1 2 3 4 5 4 3 2 1 0

11th Sep 2022, 5:41 AM
Minhaj Haider
Minhaj Haider - avatar
4 ответов
+ 3
Always show attempts with question so it would be easy to tell mistake. Here it is in C++ you can try in other language too. https://code.sololearn.com/cbKSN6WxqcjV/?ref=app
11th Sep 2022, 6:07 AM
A͢J
A͢J - avatar
+ 3
Minhaj Haider(MiDer) the sequence has the pattern of an absolute value function, n - abs(i) Now you can work out the single loop conditions of index i that will print the desired output. What starting and ending values of i will both give you zero?
11th Sep 2022, 7:03 AM
Brian
Brian - avatar
+ 1
A͢J thank you sir
12th Sep 2022, 3:31 PM
Minhaj Haider
Minhaj Haider - avatar
+ 1
Brian thanks sir
12th Sep 2022, 3:32 PM
Minhaj Haider
Minhaj Haider - avatar