I am trying to compute a really HUUUGE value...
(i am taking 1 and doubling it 64 times)
When the game of chess was invented in India, the king really liked the game, and thought it would be really useful in teaching war strategy. He offered to give the inventor whatever he wanted. The inventor asked that one grain of wheat be put on the first square, two on the second, four on the third, and so forth, doubling the number of grains on each square until all squares had been covered. At first the king was shocked by the inventor's demand for so little. But, then the king came to understand that there was not enough wheat in the entire world to cover all the squares on the chess board as the inventor had asked.
Just out of curiosity, i am trying to compute that value..
i used long int but it couldn't
get past 31st square..
here's my code:
and yeah, i need to check for NULL at fopen... too lazy to do that..
long int val = 1;
FILE *fp = fopen("results.txt", "w");
for (i = 1; i <= 64; i++)
fprintf(fp, "%2d Square %ld Grains\n", i, val);
val *= 2;
(I am just trying to save it to a text file to see the results
How do i make it work for much much bigger values? (just to
see what the answer will be for the 64th square )