How to Add Two Large Integers in C++

C++ is the popular programming language that offers all necessary features including object-oriented programming. C++ supports several types of variables including integers, floating point numbers and characters. To work with large integer numbers, C++ allows you to define a special type "long." Using this type, you may handle numbers in the range from -2147483648 to 2147483647.

Instructions

    • 1

      Assign the first integer -"238797767," for example - to a variable "number1" using the following operator:

      long number1 = 238797767;

    • 2

      Assign the second integer -"965554490", for example - to a variable "number2" using the following operator:

      long number2 = 965554490;

    • 3

      Add up the numbers with the operator

      long sum = number1 + number2;

      The variable "sum" holds the sum of two numbers.

    • 4

      Print the sum with the following command

      cout << sum;

      In this example, the result is 1204352257.

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured