Print the number series 1 -2 3 -4 5 using while loop in C
while Loop - Question 5
In this question, we will see how to print the number series 1 -2 3 -4 5 -6... up to nth term in C programming using while loop. To know more about while loop click on the while loop lesson.
Q5) Write a program in C to print the number series given below using while loop.
1 -2 3 -4 5 -6... up to nth term
Program
#include <stdio.h>
#include <conio.h>
int main()
{
    int i=1,s=1,n;
    printf("Enter nth term ");
    scanf("%d",&n);
    while(i<=n)
    {
        printf("%d ",i*s);
        s=s*-1;		// changing the sign
        i=i+1;
    }
    return 0;
}
                                Output
Enter nth term 10 1 -2 3 -4 5 -6 7 -8 9 -10