alexy0675 alexy0675
  • 02-06-2018
  • Computers and Technology
contestada

I'm doing C++. When i multiply 200000 by 200000, i get 1345294336. I wrote
long long x = 200000 * 200000
cout << x << endl;

Respuesta :

tonb
tonb tonb
  • 04-06-2018
Even though your variable x is large enough to hold the answer 40000000000, the constants 200000 are treated as integers, such that the multiplication is first fitted in an integer that is too small.

The solution is to use the 'LL' suffix on the constants, so that the compiler knows to treat them as long longs from the start:

long long x = 200000LL * 200000LL;

The number 1345294336 can be explained by ANDing 40000000000 with 0xFFFFFFFF (which is the maximum size of an unsigned long)
Answer Link

Otras preguntas

Write a java code to print Multiplication Table Till 20 HINTS: public static void main(String[ ] args) { int multiplicationTable[ ][ ]=new int [21][11];
how do I convert text to English ​
what fraction of 60 is the number 90? what fraction of 60 is the number 20? what fraction of 60 is the number 24? what fraction of 60 is the number 30?
Everything is back but not my work help please
to reads principal, time and rate to calculate simple interest and total amount​
I need help with this algebra problem!!! 28x+15y=7230
Many excellent managers help _______________ employees adjust to schedule and task changes.
10) What is 150% of 60?
Heyy everyone,HELP ME WITH THIS EXERCISE PLEASE!!! I’M NEEDING YOUR ANSWERS NOW,PLEASE HELP ME:) I WILL GIVE YOU THE BRAINLIEST IF YOU ANSWERS MY QUESTIONS VERY
what is your mother name