#include <stdio.h>

int main(void) {
    // Declare variables to store the exponent (n) and the result of 2 to the power of n.
    int n, two_to_the_n;

    // Display a header for the table.
    printf("TABLE OF POWERS OF TWO\n\n");
    printf("n      2 to the n\n");
    printf(" ---- ---------------\n");

    int i = 0;

    // Loop through the powers of two while the user hasn't input five numbers.
    while (i < 5) {
        // Prompt the user to input a number.
        printf("Enter number %d: ", i + 1);
        scanf("%d", &n);

        // Initialize two_to_the_n with the base value of 1.
        two_to_the_n = 1;

        // Loop to calculate the power of two for the entered number.
        int j = 0;
        while (j <= n) {
            // Calculate the next power of two by multiplying the previous one by 2.
            two_to_the_n *= 2;
            ++j;
        }

        // Display the current values of n and 2 to the power of n in a formatted way.
        printf("%2d           %d\n", n, two_to_the_n);

        // Increment the counter for the loop.
        ++i;
    }

    // Indicate successful execution by returning 0.
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: