0

How to display the first ten series: 1,--3,5,-7,9,.............

The first term of the series must be positive and then negative and then positive and then so on.

30th Jul 2018, 5:56 PM
Madhubala
3 Respostas
+ 5
Like this? for (int i = 1, count = 0; count < 10; i+=2) { System.out.print((count % 2 == 0 ? "" : "-") + i + " "); count++; }
30th Jul 2018, 7:14 PM
ReimarPB
ReimarPB - avatar
+ 3
(-1)**(n%2)*(2*n+1)
30th Jul 2018, 8:03 PM
Flandre Scarlet
Flandre Scarlet - avatar
0
Hint: The nth element of the series is equal to a_{n-1}+4*n*(-1)^n
30th Jul 2018, 6:22 PM
Bebida Roja
Bebida Roja - avatar