#include <stdio.h>
int main(int argc, char *argv[]) {
/**
* Prints out powers of 2 for 32 iterations.
*/
int iterations = 0;
int value = 1;
while (iterations <= 32) {
// Prints in this format: iterations 2^n value
printf("%d\t2^%d\t%d", iterations, iterations, value);
switch (iterations) {
case 8:
case 16:
case 32:
printf("\t\t%d bit\n", iterations);
break;
default:
printf("\n");
break;
}
value *= 2;
++iterations;
}
return 0;
}
When I compile and run this piece of code, weird stuff happens when I print 'value' after it is larger than 2^30, even when I declare it as an unsigned long.
What do I do? I am simply a beginner. :-(