Why the output of my program is "0" when I multiply large numbers like 256 and 8192 i

This is a discussion on Why the output of my program is "0" when I multiply large numbers like 256 and 8192 i within the C Programming forums, part of the General Programming Boards category; Hi. Could someone help me. I am making a C language program that will display the product of any large ...

Turbo C was set to the AT&T standard, in it's earliest versions, and had only unsigned long int as it's highest integral data type. I'm not sure what the later versions of Turbo C had.

For a larger number, you could:

1) Check out limits.h and see what your largest double is. Use the double if it's big enough, and then round off the double, and print only the part to the left of the decimal point.

2) Use an array of digits (char or int), to hold your big int's. You'll have to write up your own functions to handle addition, subtraction, multiplication and division, and anything else you want. Not too bad for the basics, but if you want higher math functions, use #3.

3) Get a large number library. GNU has one that's well known. Laserlight linked to it just last week, here.

Using an unsigned int will effectively double the range of your positive int's, but eleven digits is a reach.

Oh. That's a big help. I am actually using this sample program as a reference to my real program. Our professor wants us to make a program that will output this using the function call.
1 2 2 4 8 32 256 8192 2097152 17179869184
I have made a program, but as of now, I got the 1st to the 9th element, my problem is on the 10th and last element. Can a 2-dimensional long array do it?

So you may be able to use the #1 technique then. That would be a lot easier than anything else.

To make it work declare your variables as doubles, and do the exponentiation of 2, as you need to (21 times I believe). Your answer might be OK, because it's a power of 2. If it needs to be rounded, add 0.5 to it and then divide by 1, to round it off.

Give that a shot.

I'm getting that sneaky feeling that there is a bit based, power of 2, super easy answer to this, but I don't know it. Did your prof mention something like this, and like to be "sneaky"?

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

Only if you don't notice what the pattern actually is. But yes, bit shifting is only going to work if he's got 21 bits there for him to shift into; shifting a 1 off the edge of the register and down to the bottom of the computer case doesn't help.

Only if you don't notice what the pattern actually is. But yes, bit shifting is only going to work if he's got 21 bits there for him to shift into; shifting a 1 off the edge of the register and down to the bottom of the computer case doesn't help.

Oh WOW... after all these years... I finally know where all that dust in my computer cases comes from!