[CHALLENGE]🏆 Print the following series | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 12

[CHALLENGE]🏆 Print the following series

📑 Description: Print numbers in alternating order. You should take a number as input : >> 5 And your output should be : >> [0,5,1,4,2,3] Let's take another input as : >> 10 And, your output should be: >> [0,10,1,9,2,8,3,7,4,6,5,5] ✨ Hint: Every two consecutive numbers add up to give the input 🔖 Note: Your output list should have even number of terms Best of luck 👍 # Happy coding

5th Dec 2017, 9:51 AM
#RahulVerma
#RahulVerma - avatar
26 Answers
+ 33
//here is my try ☺ //no loops used ☺ //1 loop , 2 loop methods are in comment 😁 //works for +ve as well as -ve https://code.sololearn.com/c9DXjEre07Mx/?ref=app
5th Dec 2017, 10:30 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
5th Dec 2017, 10:10 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
5th Dec 2017, 9:28 PM
LukArToDo
LukArToDo - avatar
5th Dec 2017, 11:47 AM
David Akhihiero
David Akhihiero - avatar
5th Dec 2017, 2:06 PM
Justine Ogaraku
Justine Ogaraku - avatar
+ 11
https://code.sololearn.com/cKV6T6xnho4u/?ref=app
5th Dec 2017, 11:25 AM
Cool Codin
Cool Codin - avatar
+ 11
Wow, I'm late 😩. But challenge accepted 😁👊
5th Dec 2017, 2:05 PM
Justine Ogaraku
Justine Ogaraku - avatar
5th Dec 2017, 2:20 PM
Kartikey Sahu
Kartikey Sahu - avatar
+ 10
Here's my try in c++: https://code.sololearn.com/c533DeTkBLA4/#cpp Hope you like it :D
5th Dec 2017, 10:10 AM
Maya
Maya - avatar
7th Dec 2017, 3:43 AM
Käzî Mrîdùl Høssäîn
Käzî Mrîdùl Høssäîn - avatar
+ 7
Here is code for -ve integers as well as +ve integers... https://code.sololearn.com/c7H6zO3RfFQf/?ref=app
14th Dec 2017, 6:44 PM
Ajay Gaikwad
Ajay Gaikwad - avatar
+ 6
https://code.sololearn.com/cHj46Wn9ebj9/?ref=app
5th Dec 2017, 11:08 AM
...
+ 6
https://code.sololearn.com/c6URikzTr1ej/?ref=app I created the codes and a full explanation of my entire logic throughout all the process. Enjoy it.
5th Dec 2017, 1:41 PM
Jonathan Álex
Jonathan Álex - avatar
+ 6
@#RahulVerma, Thanks for clarifying, will try to get it done ;) (Edit) Here's my attempt at the challenge: https://code.sololearn.com/c49QHpiyN1TA/?ref=app
6th Dec 2017, 6:10 AM
Ipang
15th Dec 2017, 3:15 AM
I'm_Groot
I'm_Groot - avatar
+ 5
#include <iostream> using namespace std; int main() { int n; cin>>n; for(int i=0,j=n;(i<=n/2)&&(j>=n/2);i++,j--) { cout<<i<<" "<<j<<" "; } return 0; }
5th Dec 2017, 10:49 AM
Suhail P Salim
Suhail P Salim - avatar
5th Dec 2017, 10:54 AM
Suhail P Salim
Suhail P Salim - avatar
+ 5
https://code.sololearn.com/W3TpSCB1htu0/?ref=app
5th Dec 2017, 2:54 PM
RZK 022
RZK 022 - avatar
+ 5
Sorry, just wanted confirmation, on the first example (5) we have 6 items, including zero. But on the second example (10), I see a twin of five, at the end of the list, which means it was not merely a number sequence. My question is, those twins, when do we need to have/create a twin number? like if they are at the center of the list? Thanks :)
6th Dec 2017, 4:54 AM
Ipang