How can i represent(store) large numbers in C of length upto 100 digits or more?
Or alternatively.,
Is there any way to store a series in a variable(and not array since i have to make an array of series itself)
How can i represent(store) large numbers in C of length upto 100 digits or more?
Or alternatively.,
Is there any way to store a series in a variable(and not array since i have to make an array of series itself)
You can do it by storing the numbers as strings , here is an example for summing the numbers that are represnet that way (its in c++ but should be easy enough to convert it to c):
string add (string &s1, string &s2){
int carry=0,sum,i;
string min=s1,
max=s2,
result = "";
if (s1.length()>s2.length()){
max = s1;
min = s2;
} else {
max = s2;
min = s1;
}
for (i = min.length()-1; i>=0; i--){
sum = min[i] + max[i + max.length() - min.length()] + carry - 2*'0';
carry = sum/10;
sum %=10;
result = (char)(sum + '0') + result;
}
i = max.length() - min.length()-1;
while (i>=0){
sum = max[i] + carry - '0';
carry = sum/10;
sum%=10;
result = (char)(sum + '0') + result;
i--;
}
if (carry!=0){
result = (char)(carry + '0') + result;
}
return result;
}