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!

Recommended Answers

All 2 Replies

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 ;

}

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.