- 论坛徽章:
- 0
|
我是C语言菜鸟,写一个小程序求最大公约数的.
为了能够处理一些比较大的数,我用长整型来定义变量的.
结果出现了 Type mismatch in redeclaration of 'gcd' 错误,
也就是我的求最大公约数那个函数出现了"重定义类型不匹配"的错误
(gcd是我自己写的一个函数).也就是说,我的程序再用整型定义
变量时,是没有问题的.(当然是输入的值不要超过turboc2.0中
规定的整型变量范围的最大值).附录程序如下,请大侠帮手:
/* This program is designed for computing great common divisor of
two positive long integers */
/* Euclidean algorithm */
#include <math.h>;
void main()
{
/*input a & b; */
long int a, b;
long int temp;
long int rm;
printf(" lease input a positive long integer:\n" ;
scanf("%d",&a);
printf(" lease input the second long integer:\n" ;
scanf("%d",&b);
/* compare a & b; */
if(a<b)
{
temp=b;
b=a;
a=temp;
}
rm=gcd(a,b);
printf("The great common divisor of a and b is: %d\n", rm);
}
long int gcd(long int a, long int b)
{
long int r0,r1,r;
long int q;
r0=a;
r1=b;
r=b;
while(r>;0)
{
q=r0/r1;
r=r0-q*r1;
r0=r1;
r1=r;
}
return (r0);
} |
|