#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");
// Initialize two_to_the_n with the base value of 1.
two_to_the_n = 1;
// Loop through the powers of two for n from 0 to 10.
for (n = 0; n <= 10; ++n) {
// Calculate the next power of two by multiplying the previous one by 2.
two_to_the_n *= 2;
// Display the current values of n and 2 to the power of n in a formatted way.
printf("%2i %i\n", n, two_to_the_n);
}
// Indicate successful execution by returning 0.
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: