// wheat.c -- exponential growth
#include <stdio.h>

const int SQUARES = 64;
const float CROP = 1e15;

int main(void)
{
	double current, total;
	int count = 1;

	printf("square   grains added   total grains   fraction of\n");
	printf("                                       US total\n");
	// start with one grain
	total = current = 1.0;

	while (count <= SQUARES)
	{
		// print out current state
		printf("%4d %15.2e %13.2e %13.2e\n", count, current, total,
			total / CROP);

		count = count + 1;
		// double grains on next square
		current = 2.0 * current;
		// update total
		total = total + current;
	}
	return 0;
}