How to Handle Large Numbers in C? Last Updated : 12 Jun, 2024 Comments Improve Suggest changes Like Article Like Report 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: 111111111011111111100Working with Big Numbers in CTo 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. C Program to Handle Large NumbersThe below example demonstrates the use of arrays to handle large numbers in C. C // C program to handle large numbers #include <stdio.h> #include <string.h> // Function to add two large numbers void addLargeNumbers(char* num1, char* num2) { int len1 = strlen(num1); int len2 = strlen(num2); int carry = 0; int i; // Make both numbers of equal length while (len1 < len2) { // Prepend zero in num1 memmove(num1 + 1, num1, len1 + 1); num1[0] = '0'; len1++; } while (len2 < len1) { // Prepend zero in num2 memmove(num2 + 1, num2, len2 + 1); num2[0] = '0'; len2++; } // Add digits from right to left for (i = len1 - 1; i >= 0; i--) { int digit = (num1[i] - '0') + (num2[i] - '0') + carry; num1[i] = (digit % 10) + '0'; carry = digit / 10; } // If there is a carry after adding all digits if (carry) { memmove(num1 + 1, num1, len1 + 1); num1[0] = carry + '0'; } } int main() { char num1[100] = "9999999999999999999999999999999999999" "9999999999999999999999999999999999999" "99999999999999999999999999"; char num2[100] = "1"; addLargeNumbers(num1, num2); printf("Sum: %s\n", num1); return 0; } OutputSum: 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. Comment More infoAdvertise with us Next Article How to Take Multiple Input in C? D denzirop9v Follow Improve Article Tags : C Programs C Language c-input-output C Examples Similar Reads C Program For Char to Int Conversion Write a C program to convert the given numeric character to integer.Example:Input: '3'Output: 3Explanation: The character '3' is converted to the integer 3.Input: '9'Output: 9Explanation: The character '9' is converted to the integer 9.Different Methods to Convert the char to int in CThere are 3 mai 3 min read C Program For Int to Char Conversion To convert the int to char in C language, we will use the following 2 approaches: Using typecastingUsing sprintf() Example: Input: N = 65 Output: A1. Using TypecastingMethod 1:Declaration and initialization: To begin, we will declare and initialize our integer with the value to be converted.Typecast 2 min read How to Take Multiple Input in C? In C, we use scanf to take input from the user, and often it is necessary to take multiple inputs simultaneously. In this article, we will learn about how to take multiple inputs from the users in C. Multiple Inputs From a User in CTo take multiple inputs from users in C, we can declare an array to 2 min read Converting String to Long in C Here, we will see how to build a C Program For String to Long Conversion using strtol() function. Syntax: long int strtol(char *string, char **ptr, int base)The first argument is given as a stringThe second argument is a reference to an object of type char*The third argument denotes the base in whic 4 min read C Program to Find the Size of int, float, double and char Write a C program to find the size of the data types: int, float, double, and char in bytes and print it on the output screen.ExamplesInput: charOutput: Size of char: 1 byteInput: intOutput:Size of int: 4 bytesDifferent Methods to Find the Size of int, float, double and char in CWe can find the size 4 min read Convert String to int in C In C, we cannot directly perform numeric operations on a string representing a numeric value. We first need to convert the string to the integer type. In this article, we will discuss different ways to convert the numeric string to integer in C language.Example:Input: "1234"Output: 1234Explanation: 6 min read Like