0

Well I know that itoa and sprintf are there for this task, but all these require a pre-defined size of int (like int , long int, long long int), but what if I need to add or subtract something from factorial of 99, which is let's say stored in a char string s[200]; (and that is beyond the limits of even long long int).....what should I do???

6565850
  • 3
  • 1

1 Answers1

0

one of the way to handle such large numbers is to use integer array. such as

int a[200]

and perform operations on the array as you perform operations on numbers using basic arithmetic of considering each digit of a number i.e for example consider multiplying 2 numbers 1234*4567 what you do is, store 1234 in a[] and 4567 in b[]. use a temporary array c[] then,

4*7=28 so next
3*7+2(which can be computed as (int)28/10)=23
2*7+2=16
1*7+1=8

so you get 8638 in first iteration store it in c[] then, do the same using 6 i.e 1234*6 and do 8638+1234*6*10 i think now you got this basic maths. use this type basic maths method to perform operations on large numbers stored in array. all operation can be implemented by using such digit level operations.

LearningC
  • 3,182
  • 1
  • 12
  • 19
  • but how would I add even the integer array??? suppose last three digits are 4, 6, 7 how would I do normal addition??? – 6565850 Mar 12 '14 at 14:46
  • @6565850 i have explained how to multiply large numbers. addition is also same add the numbers digit wise. – LearningC Mar 12 '14 at 15:52