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

A serum is being given to a patient to desensitize the patient for allergies. Each week the dosage is increased by 0.01 centiliters (cL). If the patient receive
what is 1/6 in decimal
A company sells cookies in 250-gram packs. When a particular batch of 1,000 packs was weighed, the mean weight per pack was 255 grams and the standard deviation
If the sperm gamete that fertilizes an egg has a(n) _____ chromosome, it will form male offspring. X Y XY XX
what is 4/20 simplified
what are 6 traits of a good scientific observer
Write 3,604,839,007 in expanded form
which is another way to write the number 47
Describe the process you would use to find the solution to the problem 3 1/4 1 1/3− . Express your answer numerically and with a graphical representation.
7849 rounded with the 7 underlined