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

When this 3-digit number is rounded to the nearest ten or hundred, the numbers round up.  All of the digits in this number are the same.  The sum of the digits
When this 3-digit number is rounded to the nearest hundred, it rounds to 200.  Rounded to the nearest ten, this number rounds to 200.  The sum of the digits of
simplify the expression w+14w-6w & 3a²+6a+2b²
A measure of output per unit of input such as labor is called ______.
Name the subset(s) of real numbers to which each number belongs. Then order the numbers from least to greatest. The square root of 105, -4, 4/3
Simplify square root of 72
Simplify square root of 72
Where are slides placed on a microscope?
There are five types of grains of sand: very coarse, coarse, medium, fine, and very fine. A grain of fine sand can have a diameter of 0.125 millimeters. Which n
write in expanded form 0.450