Large numbers

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2009
Posts: 14
Reputation: kostasxx is an unknown quantity at this point 
Solved Threads: 0
kostasxx kostasxx is offline Offline
Newbie Poster

Large numbers

 
0
  #1
Jun 18th, 2009
Hi

I use Dev - C++

and i d like to ask you cause i dont seem to figure that out, how can i store a 12 digit number?

For example lets say this is the number 930342900243

How can i write a program that would print that number using a variable?

Thanks
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1,488
Reputation: William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of 
Solved Threads: 123
Sponsor
William Hemsworth William Hemsworth is offline Offline
Nearly a Posting Virtuoso

Re: Large numbers

 
0
  #2
Jun 18th, 2009
Trying using the long long or __int64 integer type.
I need pageviews! most fun profile ever :)
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 14
Reputation: kostasxx is an unknown quantity at this point 
Solved Threads: 0
kostasxx kostasxx is offline Offline
Newbie Poster

Re: Large numbers

 
0
  #3
Jun 18th, 2009
so you mean use long long or __int64 like for example

long long variable; or __int 64 variable;

variable = value;

display variable?

if yes that didnt work for me in both cases.

If im wrong can you please send some code so that i can understand better what you mean?

thanks
Last edited by kostasxx; Jun 18th, 2009 at 12:49 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1,488
Reputation: William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of 
Solved Threads: 123
Sponsor
William Hemsworth William Hemsworth is offline Offline
Nearly a Posting Virtuoso

Re: Large numbers

 
0
  #4
Jun 18th, 2009
  1. #include <stdio.h>
  2.  
  3. int main( void ) {
  4. // how can i store a 12 digit number?
  5. long long num = 123456789123;
  6.  
  7. // print that number using a variable
  8. printf( "%lld", num );
  9.  
  10. return 0;
  11. }
I think that's right, hope this helps.
Last edited by William Hemsworth; Jun 18th, 2009 at 1:24 pm.
I need pageviews! most fun profile ever :)
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 14
Reputation: kostasxx is an unknown quantity at this point 
Solved Threads: 0
kostasxx kostasxx is offline Offline
Newbie Poster

Re: Large numbers

 
0
  #5
Jun 18th, 2009
i used your code but again:

[Warning] integer constant is too large for "long" type

i think i should stop using dev, maybe its dev's problem? Should i use another compiler?

any recommendation?
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Large numbers

 
0
  #6
Jun 18th, 2009
What compiler are you using?
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1,488
Reputation: William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of 
Solved Threads: 123
Sponsor
William Hemsworth William Hemsworth is offline Offline
Nearly a Posting Virtuoso

Re: Large numbers

 
0
  #7
Jun 18th, 2009
Originally Posted by wildgoose View Post
What compiler are you using?
How could you not guess from post #5?
I need pageviews! most fun profile ever :)
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 5
Reputation: darkphotn is an unknown quantity at this point 
Solved Threads: 0
darkphotn darkphotn is offline Offline
Newbie Poster

Re: Large numbers

 
0
  #8
Jun 18th, 2009
long long blahblahquack = 930342;

blahblahquack *= 1000000;

blahblahquack += 900243;

do_something(blahblahquack);


-----

or you could make a function:

long long from_thousands(int a, int b, int c, int d, int e){
long long ans = 0;
ans += a; ans *= 1000;
ans += b; ans *= 1000;
ans += c; ans *= 1000;
ans += d; ans *= 1000;
ans += e;
}

long long blahblahquack = from_thousands(0,930,342,900,243);

If you want to code it in C#, the code is cleaner -- use an object[] .
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1,488
Reputation: William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of 
Solved Threads: 123
Sponsor
William Hemsworth William Hemsworth is offline Offline
Nearly a Posting Virtuoso

Re: Large numbers

 
0
  #9
Jun 18th, 2009
>If you want to code it in C#, the code is cleaner -- use an object[]
Don't bother suggesting another language, we're in the C forum and we can assume the OP wants to use C, unless he says so himself that he's undecided.

Either way, that post didn't solve his problem. I don't use Dev, but your best bet would be to search the problem on google.
I need pageviews! most fun profile ever :)
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Large numbers

 
0
  #10
Jun 18th, 2009
There are many Dev IDE's but the typical Dev refers to Visual Studio 6.0 not newer! That version did not support long long. And math with 64-bit data had to be done in assembly language!

It also had trouble with long int. And it equated long the same as int thus both 32-bit.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC