我怎样才能将很大的数字相乘C ++ [英] How can I multiply really big numbers c++

查看:89
本文介绍了我怎样才能将很大的数字相乘C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码

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

这些乘以后得到的结果是-1431223188,这不是答案.我怎样才能给我正确的答案?

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

推荐答案

正如Jarod42所建议的那样完全可以,但是我不确定是否会发生溢出?

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

这篇关于我怎样才能将很大的数字相乘C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆