/* Program: twos.c Author: Samuel A. Rebelsky Purpose: A somewhat inefficient way of printing the powers of two from 20 down to 0. */ #include #define NUM_POWERS 21 #define BASE 2 typedef struct powinfo { int pow; int val; } powinfo; int main() { int i; // Counter variable for loops powinfo powers[NUM_POWERS]; // Powers of two // Fill in the powers array powers[0].pow = 0; powers[0].val = 1; for (i = 1; i < NUM_POWERS; i++) { powers[i].val = powers[i-1].val * BASE; powers[i].pow = i; } // Print out the results for (i = NUM_POWERS-1; i >= 0; --i) { printf("%d^%d:\t%d\n", BASE, powers[i].pow, powers[i].val); } } // main()