Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Division operation not giving the right result

i’m having a problem with this operation that is not really giving the right result.
The result is 60216 on terminal, but it should be 563376.

int a = 8536;
int b = 563376;
int d = 8536;
unsigned long long int k = (a*b);
cout << k/d << endl;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

you need long long everywhere

long long int a = 8536;
long long int b = 563376;
long long int d = 8536;
unsigned long long int k = (a * b);
std::cout << k / d << std::endl;

note that its nothing to do with division. THis

int a = 8536;
 int b = 563376;
unsigned long long int k = (a * b);
std::cout << k  << std::endl;

gives the wrong answer too

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading