Sublime Sequence
Practice this coding question on Coding Gurukul.
Problem statement
Farmer John has an integer 𝑥.He creates a sequence of length 𝑛 by alternating integers 𝑥 and −𝑥 ,starting with 𝑥. For example, if 𝑛=5 , the sequence looks like: 𝑥,−𝑥,𝑥,−𝑥,𝑥. He asks you to find the sum of all integers in the sequence. Sample explanation: NA
Input format
The only line of input for each test case is two integers 𝑥 and 𝑛 (1≤𝑥,𝑛≤10).
Output format
output the sum of all integers in the sequence.
Constraints
(1≤𝑥,𝑛≤10).
Sample input
1 4
Sample output
0
Sign in to run or submit a solution in C++, Java or Python.