jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
a "long long" data type is a 64 bit number, and gives
Signed min: -9223372036854775808
Signed max: 9223372036854775807
Unsigned max: 18446744073709551615
.
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
the format specifier for a long long int is
long long myBigNum=600851475143;
printf("the number is: %lld\n",myBigNum);
.
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
[IMG]http://img8.imageshack.us/my.php?image=devsnap.png[/IMG]
Im still not able to get the precision required
i dont know why not.
i'm using GCC v3.4, which is over 3 years old.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
unsigned long long bignum = 600851475143 ;
printf("bignum : %lld\n",bignum);
printf("bignum * 2: %lld\n",bignum * 2);
printf("bignum * 4: %lld\n",bignum * 4);
return 0;
}
gives the following result:
bignum : 600851475143
bignum * 2: 1201702950286
bignum * 4: 2403405900572
Process returned 0 (0x0) execution time : 0.050 s
Press any key to continue.
you're either doing something wrong, or your compiler sucks or something.
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
Can you tell me, why is it wrong?? You can very well use atoi function. for converting characters to numbers
beat it, kid. your answer isn't just wrong, it's completely irrelevant.
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
I got so frustrated over the issue and did it in PYTHON. But Yes , there is a wqay of using srings to handle large integers but I guess my compiler is the culprit. Guys. - Let me know of a decent compiler and where to download it
there absolutely is a way to do it with 64-bit integers. C99 standard defines the 64-bit integer as the long long int data type.
i do not have any problem using this data type with my compiler, GCC version 3.4. I believe GCC current version is up to 4.3.
apparently, although i have not verified this personally, Windows and Borland compilers define the long long int as __int64 ... http://home.att.net/~jackklein/c/inttypes.html#long_long
now you can either listen to some clown who wants you to create a string-based big integer handler from scratch, or you can use the 64-bit integer data type that is defined in the C99 standard. your current compiler may not adhere to this standard, but there are plenty that do.
http://www.codeblocks.org/
http://gcc.gnu.org/
http://www.mingw.org/
.
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179