C examples for Array:Array Value
Use a for loop to set the values, and, for variety, use a do while loop to display the values.
#include <stdio.h> int main(void) { int powers_of_2[8]; int power = 1;/* w w w .ja va2 s . c o m*/ int i; for (int i = 0; i < 8; i++) { power *= 2; powers_of_2[i] = power; } printf("Powers of 2:\n"); i = 0; do { printf("%d ", powers_of_2[i]); i++; } while (i < 8); printf("\n"); return 0; }