/* C Primer Plus 指数增长 */
#include <cstdio>
#define SQUARES 64
int main() {
const double CROP = 2E16;
double current, total;
int count = 1;
printf("square grains total fraction of\n");
printf(" added grains world total\n");
total = current = 1.0;
while (count < SQUARES) {
printf("%4d %13.2e %12.2e %12.2e\n", count, current, total, total / CROP);
count += 1;
current *= 2.0;
total += current;
}
return 0;
}
运行结果