Computer Science, asked by shubnegi1004, 1 day ago

wap to print (1,-3,5,-7 to n) in C-language

Answers

Answered by anindyaadhikari13
4

Solution:

The given cøde is written in C.

#include <stdio.h>

int main(){

int n,i,a=1,c=1;

printf("Enter n - ");

scanf("%d",&n);

for(i=0;i<n;i++,a+=2,c*=-1)

printf("%d ",c*a);

return 0;

}

Logic:

  • Ask the user to enter the limit.
  • Initialise a=1, c=1
  • Iterate a loop n times.
  • Display value of c × a.
  • Increment value of a by 2.
  • Negate the value of c as terms are either positive or negative.

See the attachment for output.

Attachments:
Similar questions