divide big numbers

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2008
Posts: 35
Reputation: &rea is an unknown quantity at this point 
Solved Threads: 0
&rea &rea is offline Offline
Light Poster

divide big numbers

 
0
  #1
Aug 5th, 2008
hello,

I have get through this problem, I want to divide these numbers but the result calculated by c++ is not right. I am quite sure it is due to the type of the variables but I don't know how to solve it.

  1. unsigned long long u40=16825420246;
  2. unsigned long long u20=3171426;
  3. unsigned long long prod=u20*u20;
  4. double kx; //I have also proved with float but the problem still remains
  5.  
  6. kx=u40/prod;

Could anyone of you help me?
Thanks in advanced!
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 334
Reputation: Prabakar is on a distinguished road 
Solved Threads: 29
Prabakar's Avatar
Prabakar Prabakar is offline Offline
Posting Whiz

Re: divide big numbers

 
0
  #2
Aug 5th, 2008
Perhaps this:

  1. #include<iostream>
  2.  
  3. int main ()
  4. {
  5. unsigned long long u40=16825420246llu;
  6. unsigned long long u20=3171426llu;
  7. unsigned long long prod=u20*u20;
  8. double kx;
  9.  
  10. kx=double(u40)/prod;
  11. std::cout<< "u40: "<<u40<<" u20: "<< u20
  12. <<" Prod: "<<prod<<" kx: "<<kx;
  13. std::cin.get() ;
  14. return 0 ;
  15.  
  16. }
Last edited by Prabakar; Aug 5th, 2008 at 11:37 am.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 35
Reputation: &rea is an unknown quantity at this point 
Solved Threads: 0
&rea &rea is offline Offline
Light Poster

Re: divide big numbers

 
0
  #3
Aug 5th, 2008
Thank you so much!It works!
I mark it as solved
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 1441 | Replies: 2
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC