943,696 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1022
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Jun 8th, 2009
0

can long long stor 12 dig num?ifno, without array how 2 do?

Expand Post »
can long long store 12 digit numbers.
Its showing in my comp that limit of long long is 9223372036854775807, but then it's showing too large when i declare it like this:
long long num;
i don't want to store in array.
My seniors told that long long will do but i am having trouble.
please help.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Aseem_Pandey is offline Offline
10 posts
since May 2009
Jun 8th, 2009
0

Re: can long long stor 12 dig num?ifno, without array how 2 do?

a) post what you actually tried, not a description.
b) post your actual error messages
c) tell us what your OS/Compiler is.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Jun 8th, 2009
0

Re: can long long stor 12 dig num?ifno, without array how 2 do?

From this thread I would suggest you to use: unsigned long long

>can long long store 12 digit numbers.
Depends on what your compiler is...
Last edited by tux4life; Jun 8th, 2009 at 4:31 pm.
Reputation Points: 2125
Solved Threads: 243
Postaholic
tux4life is offline Offline
2,105 posts
since Feb 2009
Jun 8th, 2009
0

Re: can long long stor 12 dig num?ifno, without array how 2 do?

this is my code. Problem as described above.
We have to find largest prime factor of a number.
C++ Syntax (Toggle Plain Text)
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.  
  6. long long num=600851475143,large,k,i;
  7.  
  8. for(i=2;;++i)
  9. { k=i;
  10. if(num%i==0)
  11. { num/=i;
  12. i=k-1;
  13. large=k;
  14. }
  15. if(num==1)
  16. break;
  17. }
  18. cout<<large;
  19. return 0;
  20. }
the error i get is:
integer constant is too large for ‘long’ type
i don't want to use array.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Aseem_Pandey is offline Offline
10 posts
since May 2009
Jun 8th, 2009
0

Re: can long long stor 12 dig num?ifno, without array how 2 do?

unsigned long long gives same error.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Aseem_Pandey is offline Offline
10 posts
since May 2009
Jun 8th, 2009
0

Re: can long long stor 12 dig num?ifno, without array how 2 do?

>i don't want to use array.
In that case there's probably no other choice left than choosing for a Big Number library like GNU MP, it can handle much bigger numbers than a standard C++ datatype can...

And take a look at Salem's post as well:
  • What is your compiler?
  • What is your OS?
Last edited by tux4life; Jun 8th, 2009 at 4:36 pm.
Reputation Points: 2125
Solved Threads: 243
Postaholic
tux4life is offline Offline
2,105 posts
since Feb 2009
Jun 8th, 2009
2

Re: can long long stor 12 dig num?ifno, without array how 2 do?

Try to append LL suffix to long long constants.
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Jun 8th, 2009
0

Re: can long long stor 12 dig num?ifno, without array how 2 do?

Try
long long num=600851475143LL,large,k,i;
to tell the compiler that the constant is a long long.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Jun 8th, 2009
0

Re: can long long stor 12 dig num?ifno, without array how 2 do?

ubuntu 8.10
compiler g++ 4:4.3.1
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Aseem_Pandey is offline Offline
10 posts
since May 2009
Jun 8th, 2009
0

Re: can long long stor 12 dig num?ifno, without array how 2 do?

thanks man, a million thanks. It works
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Aseem_Pandey is offline Offline
10 posts
since May 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Stack overflow issue
Next Thread in C++ Forum Timeline: VC++ 6.0: Outputting value in register?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC