Using long arithmetic in C++ programming language
Автор: Xolmirzayev I., Xashimov A., Akbarov N.
Журнал: Экономика и социум @ekonomika-socium
Рубрика: Информационные и коммуникативные технологии
Статья в выпуске: 5 (48), 2018 года.
Бесплатный доступ
In this article there is given a way how to solve problems which is working with huge numbers in many programming languages. In Solving these problems we use “Long arithmetic ”method in C++ programming language. Using this method can help to solving mathematic and managment problems and create a new programs, working with mikrocontrollers, also provide for working programs truely.
Program, elementary function, long arithmetic, fulfill subtraction, multiplication, division, cryptography, vector-type, mathematical and financial questions, sports programming
Короткий адрес: https://sciup.org/140238838
IDR: 140238838
Текст научной статьи Using long arithmetic in C++ programming language
Nowadays, demands for computer programs are increasing day by day. In the meantime, we face up to several problems while creating new programs and try to find the ways of solving them on time. One of these problems is working with huge numbers. In order to find solution for these problems, we are using C++ programming language. There are various types that work with numbers in this programming language. These types are demonstrated in the following table. (Table-1)
Type |
Volume, bayt |
Border |
unsigned short int |
2 |
0 – 65535 |
short int |
2 |
-32768 – 32767 |
unsigned long int |
4 |
0 – 4294967295 |
long int |
4 |
-2147483648 – 2147483647 |
int (16 razryad) |
2 |
-32768 – 32767 |
int (32 razryad) |
4 |
-2147483648 – 2147483647 |
unsigned int (16 razryad) |
2 |
0 – 65535 |
unsigned int (32 razryad) |
4 |
0 – 4294967295 |
Float |
4 |
1,2e-38 – 3,4e+38 |
Double |
8 |
2,2e-308 – 1,8e+308 |
Table-1. Types that work with numbers
If we focus on all types above, they have their own limits. It means that in calculations, we cant reach higher results because of these limits and there may appear some errors in accounts. In science, the way of solving these problems is called “long arithmetic”. In long arithmetic, not operating numbers but lines and vectors are used. We can say, this way is an adapted version of addition, subtraction, multiplication, division to the programming language.
In long arithmetic, we can fulfill subtraction, multiplication, division and other elementary functions with the help of processing machines. However, long arithmetic is widely used in the following areas:
-
• Working with microcontrollers
-
• In cryptography
-
• Mathematical and financial questions
-
• Sports programming (Olympics)
During the process of creating the program, number of problems arise in using and reading very large values. For example, if we consider the rate of the number value of 10, 500 numbers, it can’t be calculated by the number of standard variables in the program. Long arithmetic is used under similar conditions. We will analyze the program code that is done on this method.
-
1. First, we need to download to the program a list of necessary libraries.
2. Set up to use standard Namespace.
-
3. "large_number" elements "int" which is relevant to the type of vector and the "base", "int" type variable declaration.
-
4. The above declared that returns values in a vector type, adding function with two parameters that is relevant to this type.
-
5. This function also sends back values in the above stated vector type and receives styrene and vector-type parameters, and called “read”.
6. Printing the parameters of vector type and returning no values function.
7. The main part of the program.
We will download extra vector library and stdio library to C ++ programming language standard library. The reason we keep all information in vector. In common language, vector can be described as "smart array". That is, the vector also keeps the same type values as an array. The main advantage is recognized as a change in the number of vector elements dynamic.

We add x and y variables with the help of this function, x variable will be used and returned as x result.
This function adds to the end of the vector string-type s variable value to the vector type x variable value step by step converting 9 characters into x number with the help of "atoi" function. In this case, the number of type line is placed in reverse order to the vector.

We use this function when printing vector values. If you pay attention, the information in the vector is being printed in reverse order. Because the reverse was the case in vector line too. In order to have correct answer reverse order is required here as well.

Here is added and the collection of vector-type x, y, z, typical of the screen to read the data string number_1, number_2 variables are declared number_1 and number_2 them learn to read, number_1 and number_2 "read" function, x and y variables, "add" setting x variable value of the sum z mastered the "print" function in the z recognize the value.
By running the application code, as x proof we try to add the larger numbers than above stated types limit with the help of this program.
First number= 3005198612051988160120162017 Second number= 1902196403121965300508082702 The result = 4907395015173953460628244719 Для продолжения нажмите любую клавишу . . .
And we can see the program is working properly. We will be able to work with huge numbers in this program.
It can be concluded that we can work with the huge numbers using the long arithmetic program. Using long arithmetic program in solving complex questions and creating various programs ensures correct operation of the program.
Список литературы Using long arithmetic in C++ programming language
- -E.Horowitz, S.Sahni, S.Anderson-Freed, "Fundamentals of data structures in C", Second edition, University Press(India), New Delhi, 2008 y.
- -http://e-maxx.ru/algo/big_integer.