A
A
Anton Anton2018-08-24 16:24:53
C++ / C#
Anton Anton, 2018-08-24 16:24:53

How to implement multiplication of numeric values ​​in C++?

Guys, I'm completely noob in C ++, but I really want to master this language, just for myself.
In essence:
Everyone knows the history of the chessboard, more precisely with the progression of 2 to the 64th power. And so I actually decided to write a program that will display values ​​from 1 to (well, a large number is obtained there). In general, I write in 1C, and the code listing for such a task will look like this:

А 		= 1;  
  Ит 		= 1;
  Сум 	        = 0;
  
  Пока Ит <= 63 Цикл 
    Сообщить(Строка(Ит)+"---"+Строка(А));
    Сум = Сум + А;
    А 	= А*2;
    Ит 	= Ит+1;
  КонецЦикла;
  
  Сообщить(Строка(Ит)+"---"+Строка(А));
  Сум = Сум + А;
  Сообщить("Результат количество: " + Строка(Сум),СтатусСообщения.Важное);
  Сообщить("Результат вес в кг: " + Строка(Окр(Сум*0.00004,2,РежимОкругления.Окр15как20)),СтатусСообщения.Важное);
  Сообщить("Результат вес в т: " + Строка(Окр(Сум*0.00004/1000,2,РежимОкругления.Окр15как20)),СтатусСообщения.Важное);

In C++, for the life of me, I can’t implement this, the int variable type truncates the values ​​​​and nothing happens in the end

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Armenian Radio, 2018-08-24
@gbg

No standard type in crosses can accommodate a number larger than 2^64-1, so your program won't work.
You will have to deal with long arithmetic, that is, with a GMP -
type library .

G
GavriKos, 2018-08-24
@GavriKos

Use another type whose dimension will allow you to display the desired number. All sorts of unsigned long and so on.
if they are not enough - google about the mathematics of large numbers.

@
@YAnri, 2018-08-24
_

if not higher than 2^64 then you can use unsigned long long

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question