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

Translate the following sentences into French 17. She showed us her beautiful red dress. 18. We use the fax machine a lot in our office. 19. I'm sorry, I've got
A + B = C which is correct. |C| = A |C| > |A| C > 0 C < 0
Adaptability in leadership styles, depending on the task and team you are working with, is known as the:
Write a system of equations that represents the situation. The sum of two numbers is 15. The second number is equal to the first number plus 1. Let x = the fi
Plz help as fast as possible
How to compare love to a rose
20 POINTS! 1. The four types of tissue in the body are epithelial, connective, muscle, and nervous. True | False 2. Muscle tissues are bundles of muscle fibers
53х - 1015. х - 3x —10x-(3x -3​
Find the lateral surface area of the prism. 1.5ft 3ft 4ft
(Vosotros) ___ de Miami.