C PROGRAM TO GENERATE A SERIES WHERE ODD POSITIONS ARE MULTIPLE OF 2 AND EVEN POSITIONS ARE DIVIDED BY 2 FROM PREVIOUS VALUE

   

 

Consider the following I/O samples.


SAMPLE INPUT: 10

SAMPLE OUTPUT: 0 0 2 1 4 2 6 3 8 4



C PROGRAM:

#include<stdio.h>

int main()

{

    int n,i;

    scanf("%d",&n);

    printf("\n");

    for(i=1;i<=n;i++)

    {

        if(i%2==1)

            printf("%d ",i-1);

        else

            printf("%d ",(i/2)-1);

    }

    return 0;

}


OUTPUT:







The given source code in C program "TO GENERATE A SERIES WHERE ODD POSITIONS ARE MULTIPLE OF 2 AND EVEN POSITIONS ARE DIVIDED BY 2 FROM PREVIOUS VALUE" is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free. 

If you have any feedback about this article and want to improve this, please comment in the comment section.




Comments

Popular posts from this blog

INVERTED PYRAMID STAR PATTERN

C PROGRAM TO PRINT ALL LEAP YEARS IN A GIVEN RANGE

C PROGRAM TO PRINT THE REMAINING DAYS AND COMPLETED DAYS FROM A GIVEN DATE