Computer Science, asked by rajsaini192005, 6 months ago

Write a program to print the following series​

Answers

Answered by Manish4410
2

Answer:

Receive the value of N say 10 as input to print the series upto that given term (10 times here)

Create a for loop that runs from 1 to N.

Inside the for loop, check whether the loop variable i is greater than 1 or not.

Answered by bibliophilermumukshu
0

Input: N = 4

Output: 2, 1, 4, 3

Explanation:

Nth Term = (N % 2 == 0) ? (N - 1) : (N + 1)

1st term = (1 % 2 == 0) ? (1 - 1) : (1 + 1)

= (1 + 1)

= 2

2nd term = (2 % 2 == 0) ? (2 - 1) : (2 + 1)

= (2 - 1)

= 1

3rd term = (3 % 2 == 0) ? (3 - 1) : (3 + 1)

= (3 + 1)

= 4

4th term = (4 % 2 == 0) ? (4 - 1) : (4 + 1)

= (4 - 1)

= 3

Therefore, Series = 2, 1, 4, 3

Input: N = 7

Output: 2, 1, 4, 3, 6, 5, 8

Nth Term = (N % 2 == 0) ? (N - 1) : (N + 1)

hope it helps :)

#bebrainly

#mumukshu

Similar questions