C PROGRAM TO GENERATE A SERIES OF POWER OF 2 AND POWER OF 3 ALTERNATIVELY

   

 

Consider the following I/O samples.


SAMPLE INPUT: 10

SAMPLE OUTPUT: 1 1 2 3 4 9 8 27 16 81



C PROGRAM:

#include<stdio.h>

int main()

{

    int n,i,pow1=1,pow2=1;

    scanf("%d",&n);

    printf("\n");

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

    {

        if(i%2==1)

        {

            printf("%d ",pow1);

            pow1=pow1*2;

        }

        else

        {

            printf("%d ",pow2);

            pow2=pow2*3;

        }

    }

    return 0;

}


OUTPUT:





The given source code in C program "TO GENERATE A SERIES OF POWER OF 2 AND POWER OF 3 ALTERNATIVELY" 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