Computer Science, asked by anindyaadhikari13, 5 months ago

Good evening everyone.
Today's question.
Print this series in Java/Python.

1 3 2 4 3 5 4 6 5....N terms.
Logic:- (+2,-1, +2,-1)

Restrictions:-
1. Not to use more than 1 loop.
2. You can use only 1 print statement inside the loop.
3. Switch case, if else else if and ternary operators are not allowed.
4. Maximum number of variables you can use:- 4

It's not a challenge, solve it.
• Spammers stay away.

Shortest code given will be marked as brainliest. ​

Answers

Answered by BrainlyProgrammer
5

Answer:

Question:

Good evening everyone.

Today's question.

Print this series in Java/Python.

1 3 2 4 3 5 4 6 5....N terms.

Logic:- (+2,-1, +2,-1)

Restrictions:-

1. Not to use more than 1 loop.

2. You can use only 1 print statement inside the loop.

3. Switch case, if else else if and ternary operators are not allowed.

4. Maximum number of variables you can use:- 4

It's not a challenge, solve it.

• Spammers stay away.

Shortest code given will be marked as brainliest.

Answers:

int a=1,b=2,i;

n=Sc.nextInt();

for(i=1;i<=n;i++)

{

System.out.println(a+" ");

a=a+b;

b=-b;

b++;

}

As you said only 1 print statement in loop.... accepted

As you said max. four variables.... accepted

As you said no switch case...ternary....if-else allowed..... accepted

More than 1 loop not allowed... accepted

Shortest program possible by me

;)

Similar questions