![]() |
VOOZH | about |
In C, the maximum value that an integer type variable can store is limited. For instance, the maximum value that an long long int can hold in 64-bit compiler is 9223372036854775807. So, how can we handle numbers that are larger than this? In this article, we will learn how to handle large numbers in C.
Example:
Input: num1 = 12345678901234567890 num2 = 98765432109876543210 Output: Sum: 111111111011111111100
To handle large numbers in C, we can use arrays or strings to store individual digits of the large number and perform operations on these digits as required. String them as strings can be beneficial as each digit only takes one byte we can use the inbuilt methods to work on it.
The below example demonstrates the use of arrays to handle large numbers in C.
Sum: 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Time Complexity: O(n), where n is the number of digits in the large number.
Auxiliary Space: O(n), where n is the number of digits in the large number.
We can add more operations for this kind of number representation to make it according to our needs.