Computer Science, asked by fahimkhan40226, 4 months ago

Write a program (WAP) that will print following series upto Nth terms.
1, ‐2, 3, ‐4, 5, ‐6, 7, ‐8, 9, ‐10, 11, ‐12, 13, ‐14, …….
input: 3
output: 1, -2, 3
(Using for loop in C)

Answers

Answered by ak9696374
8

Answer:

fgyhhhh uuuu hhhhhhhhhhggffjfjdjdjdjid

Answered by tripathiakshita48
0

#

include

<stdio.h>

int

main

()

{

int

N;

printf

(

"Enter the value of N: "

);

scanf

(

"%d"

, &N);

for

(

int

i=

1

; i<=N; i++) {

if

(i%

2

==

0

) {

printf

(

"%d, "

, -i);

   }

else

{

printf

(

"%d, "

, i);

   }

 }

return

0

;

}

In this program, we first take the value of N as input from the user. Then we run a for loop from 1 to N, and for each value of i, we check whether it is even or odd using the modulo operator (%). If i is even, we print -i, else we print i.

For example, if the user inputs 3, the output will be "1, -2, 3," as expected.

Note: We use the comma after each number to separate them. If you want to remove the comma after the last number, you can modify the program accordingly.

for more such questions on C language
https://brainly.in/question/51872546
#SPJ3

Similar questions