954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Long numer data type

hello. Ive been using a pretty long number in my program . its problem3 of the euler project . Its 600851475143 . What data type do I use for this???

nagu89
Newbie Poster
9 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 
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
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

a "long long" data type is a 64 bit number, and gives

Signed min: -9223372036854775808 Signed max: 9223372036854775807 Unsigned max: 18446744073709551615

.


Thank you>>>And what is the format spec?Im working on devC++

nagu89
Newbie Poster
9 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

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
 

the format specifier for a long long int is

long long myBigNum=600851475143;

printf("the number is:  %lld\n",myBigNum);

.


Thank you

nagu89
Newbie Poster
9 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 
Thank you


[IMG]http://img8.imageshack.us/my.php?image=devsnap.png[/IMG]
Im still not able to get the precision required

nagu89
Newbie Poster
9 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

If you want to use numbers of very huge sizes i bet strings might be useful. You must perhaps use several functions for performing those operations. for eg. when you add two strings, proceed from the last digit and carry over the excess to the next digit and so on.

s_sridhar
Junior Poster
141 posts since Mar 2009
Reputation Points: 17
Solved Threads: 16
 
[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

s_sridhar
Junior Poster
141 posts since Mar 2009
Reputation Points: 17
Solved Threads: 16
 

>Jepthah Without knowing how it works, it is bad to comment. Well you know operator overloading???? and you can very well stop being rude.

s_sridhar
Junior Poster
141 posts since Mar 2009
Reputation Points: 17
Solved Threads: 16
 
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
 

Well, it's not irrelevant. Strings can be configured to handle large numbers.

s_sridhar
Junior Poster
141 posts since Mar 2009
Reputation Points: 17
Solved Threads: 16
 
Well, it's not irrelevant. Strings can be configured to handle large numbers.


Will both you guys please stop fighting and try helping me out?
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

nagu89
Newbie Poster
9 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

I don't think downloading a compiler will help. You must write those functions.

s_sridhar
Junior Poster
141 posts since Mar 2009
Reputation Points: 17
Solved Threads: 16
 
I don't think downloading a compiler will help. You must write those functions.


It seems to be working perfectly for you. what compiler or IDE are you using?

nagu89
Newbie Poster
9 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

What i meant was we can't directly use those functions and we must write those, i meant it is not compiler based but user based. if you want i'll send those codes

s_sridhar
Junior Poster
141 posts since Mar 2009
Reputation Points: 17
Solved Threads: 16
 

ok. please do

nagu89
Newbie Poster
9 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 
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
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You