C程序无法计算大数目,提示Floating point exception (core dumped)解决思路
C程序无法计算大数目,提示Floating point exception (core dumped)
下面这个程序,运行输入
100和10的时候,总是提示Floating point exception (core dumped),而输入10和2则可以计算,怎么修改?thanks!
#include <stdio.h>
int main()
{
int m, n;
void selectnum(int , int );
printf( "Enter total number of students: ");
scanf( "%d ", &m);
printf( "Enter selected number of students: ");
scanf( "%d ", &n);
selectnum(m, n);
return 0;
}
void selectnum(int m, int n)
{
int a, b, c, d;
c = m - n;
for (a = m; m > 1; m--)
a = a * (m -1);
for (b = n; n > 1; n--)
b = b * (n -1);
for (d = c; c > 1; c--)
d = d * (c - 1);
printf( "Num of select way is %d\n ", a/b/d);
}
------解决方案--------------------
int类型溢出
------解决方案--------------------
你用unsigned long 来代替
------解决方案--------------------
int 类型表示不了100!
------解决方案--------------------
用long long int
不过我的机子跑了几分钟都还没计算出来(amd athlon~2800+)
换算法,用链表
下面这个程序,运行输入
100和10的时候,总是提示Floating point exception (core dumped),而输入10和2则可以计算,怎么修改?thanks!
#include <stdio.h>
int main()
{
int m, n;
void selectnum(int , int );
printf( "Enter total number of students: ");
scanf( "%d ", &m);
printf( "Enter selected number of students: ");
scanf( "%d ", &n);
selectnum(m, n);
return 0;
}
void selectnum(int m, int n)
{
int a, b, c, d;
c = m - n;
for (a = m; m > 1; m--)
a = a * (m -1);
for (b = n; n > 1; n--)
b = b * (n -1);
for (d = c; c > 1; c--)
d = d * (c - 1);
printf( "Num of select way is %d\n ", a/b/d);
}
------解决方案--------------------
int类型溢出
------解决方案--------------------
你用unsigned long 来代替
------解决方案--------------------
int 类型表示不了100!
------解决方案--------------------
用long long int
不过我的机子跑了几分钟都还没计算出来(amd athlon~2800+)
换算法,用链表