Hi,
Is there any way to store huge numbers (for example, a number with a million digits) in a C program and be able to perform operations on it ?
Thanks..
using std::string and operator overloading, yes it is able
Hi, thanks for your reply..
Can you elaborate the procedure.. It would be very helpful if you could post a link with the mentioned approach...
Thanks :)
There are tons of freeware libraries to perform ops over arbitrary precision numbers in C and C++. Search Google for "C arbitrary precision numbers library". For example:
http://www.tc.umn.edu/~ringx004/mapm-main.html
It's not so easy to invent a new library in this area...
string num1 = "1234";
string num2 = "4567";
string sum = "";
char tmp2 = 0;
1. reverse num1 and num2
2. for 0 to string size() do
char tmp = num1[i] + num2[i] + tmp2;
tmp2 = 0;
if (tmp > '9'){
tmp-=10;
tmp2 = 1;
}
sum+=tmp;
3. reverse sum and that's it :)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.