c++integermultiplication

How can I multiply really big numbers c++


I have the following code

int i, a, z;  
i = 2343243443;  
a = 5464354324324324;  
z = i * a;  
cout << z << endl;  

When these are multiplied it gives me -1431223188 which is not the answer. How can I make it give me the correct answer?


Solution

  • As Jarod42 suggested is perfectly okay, but i am not sure whether overflow will take place or not ?

    Try to store each and every digit of number in an array and after that multiply. You will definitely get the correct answer.

    For more detail how to multiply using array follow this post http://discuss.codechef.com/questions/7349/computing-factorials-of-a-huge-number-in-cc-a-tutorial