10 digit multiplication

here i want to perform two 10 digit multiplication.I tried but not able to get desired result so any kind of help will be saluted.
Use a bigNum library.
But i want to perform it in C.
It is simple :)

1
2
3
4
5
6
7
int x = std::numeric_limits<int>::max();
int y = std::numeric_limits<int>::max();
long long z = ( long long )x * y;

std::cout << "x = " << x <<  std::endl; 
std::cout << "y = " << y <<  std::endl; 
std::cout << "z = " << z <<  std::endl; 


The result is

x = 2147483647
y = 2147483647
z = 4611686014132420609


Or you can use unsigned int and unsigned long long if you deal with unsigned numbers.

The other way is to use std::string as number representations and apply std::transfrom algorithm. :)

In C you can use character arrays instead of the class std::string.
Last edited on
Use a bigNum library written in C.
Topic archived. No new replies allowed.