获取浮点:因子代码中的溢出错误 [英] Getting Floating point: overflow error in factorial code

查看:50
本文介绍了获取浮点:因子代码中的溢出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,我在我的课程中使用Turbo C ++在Windows 95或98上我相信。它是为了解决阶乘。问题是:

A)它把它放在指数中

B)有太多的数字要算,所以我需要一种方法将每3位数字放入逗号我不要知道如何做到这一点。

C)超过1754的任何因子给计算机一个错误,上面写着:

浮点数:溢出

这里是我的程序:

i have a program that i made in my class in Turbo C++ on windows 95or98 i belive. it is made to solve for factorials. th problem is that :
A) it puts it in exponents
B) theres too many numbers to count so i need a way to put commas every 3 digits and i dont know how to do that.
C) any factorials over 1754 give the computer an error that says:
Floating point: overflow
here is my program:

展开 | 选择 | Wrap | 行号

推荐答案

1)您正在使用void main()。这是非标准的,绝对不建议。你应该使用int main()并在函数末尾返回0。


2)为了用逗号打印数字,你需要把它作为一个字符串来操作而不是数字。如果你把它当作一个字符串,那么一次打印3个字符,然后是逗号,然后重复就很容易了。


3)这些数字是指数,因为它们很大,每个都超过10个数字。


4)你的计算机让你错误,因为它大于1700!对于浮子而言太大了。您可以使用双精度来获得更高的精度,但要意识到阶乘数是巨大的。 1700! = 1700 * 1699 * 1698 * 1697 * 1696 * ... * 3 * 2 * 1.这是一个非常大的数字。你的程序不能处理比​​这大得多的数字。
1) You are using void main(). This is non-standard and definitely not advised. You should use int main() and return 0 at the end of the function.

2) In order to print the number with commas, you;d need to manipulate it as a string, not a number. If you treat it as a string, it''s an easy task to print 3 characters at a time, then a comma, then repeat.

3) The numbers are in exponents because they are huge, like 10+ digits each.

4) Your computer ives you an error because anything larger then ~1700! is too large for a float to hold. You might e able to use a double for more precision, but realize that factorial numbers are HUGE. 1700! = 1700 * 1699 * 1698 * 1697 * 1696 * ... * 3 * 2 * 1. That''s a MASSIVE number. Your program won''t be able to handle numbers much bigger than this.


我的老师说void main()适用于我们的编译器。 int main()也可以工作,但这对问题的解决是无关紧要的。


i还没有真正进入字符串,所以我在那里迷失了。


i完全意识到什么是因子,它有多大。事情是必须有一种方法:

A)摆脱指数并只显示数字和

B)展开它以便我可以展示没有错误的整数。
my teacher says that void main () works with our compiler. int main () also works but thats irrelevent to the solving of the problem.

i havent realy goten into strings yet so im lost there.

i compleatly realize what factorial is and how big it is. the thing is is that there must be a way to:
A) get rid of the exponents and just show the number and
B) expand it so that i can show the whole number without an error.


尝试使用for循环并使用int array / vector进行乘法和加法。多数民众赞成我将如何接近它!
try using for loops and do the multiplication and addition the long way using int array/vector. Thats how I would approach it!


这篇关于获取浮点:因子代码中的溢出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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