# Thread: computing a HUUUGEE value...

1. ## computing a HUUUGEE value...

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:
Code:
```#include <stdio.h>

int main()
{
int i;
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;
}

}```
and yeah, i need to check for NULL at fopen... too lazy to do that..
(I am just trying to save it to a text file to see the results
clearly)

How do i make it work for much much bigger values? (just to
see what the answer will be for the 64th square )

Thanks.

2. 64th square: 9223372036854775808

total of all squares: 18446744073709551615

3. This way worked for me
Code:
```#include <stdio.h>

int main()
{
int i;
double val = 1.0;

for (i = 1; i <= 64; i++)
{
printf("%d Square %g\n", i, val);
val *= 2;
}
return 0;
}```
- Sean

4. ## hmm

thanks... what does %g mean ? is it just for double ? or .. ?

it's showing 9.22337e+18

how do i get the number without the e+ form ?

5. i think 9.22337e+18 means
9.22337*10^18

therefore 9223370000000000000

6. ## yeah

yeah, i know that...
i was asking ... how do i make it show
9223372036854775808 ???

7. I believe you can show it that way using %.0f

- Sean

8. 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.
This is an old story. I've heard this done in both a Chinese and Japanese variety. In the Japanese (and likely Chinese) versions however, they use rice instead of wheat.

To make it show a number that huge, you basicly need to use a string and do digit by digit multiplication on the string, adding a character when you need to. Then use whatever method you want to display it.

Quzah.

thanks