Generates a table with powers of two. - C Statement

C examples for Statement:for

Description

Generates a table with powers of two.

Demo Code

#include <stdio.h>

int main (void)
{
    int two_to_the_n;

    printf("TABLE OF POWERS OF TWO\n\n");
    printf(" n     2 to the n\n");
    printf("---    ---------------\n");

    two_to_the_n = 1;/*from  ww  w .j a v  a 2  s .  co m*/
    for (int n = 0; n <= 10; ++n){
        printf("%2i           %i\n", n, two_to_the_n);
        two_to_the_n *= 2;
    }

    return 0;
}

Result


Related Tutorials