0

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.

unsigned long long u40=16825420246;
	unsigned long long u20=3171426;
	unsigned long long prod=u20*u20;
	double kx; //I have also proved with float but the problem still remains
	
	kx=u40/prod;

Could anyone of you help me?
Thanks in advanced!

2
Contributors
2
Replies
4
Views
9 Years
Discussion Span
Last Post by &rea
0

Perhaps this:

#include<iostream>

int main ()
{
    unsigned long long u40=16825420246llu;
    unsigned long long u20=3171426llu;
    unsigned long long prod=u20*u20;
    double kx;
	
    kx=double(u40)/prod; 
    std::cout<< "u40: "<<u40<<" u20: "<< u20
        <<" Prod: "<<prod<<" kx: "<<kx;
    std::cin.get() ;
    return 0 ;

}
0

Thank you so much!It works! ;)
I mark it as solved

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.