gpt4 book ai didi

c - C语言中使用Function计算GCD时出错

转载 作者:行者123 更新时间:2023-11-30 21:44:36 25 4
gpt4 key购买 nike

这段代码显示了一些语法错误,我找不到它在哪里,可能是在 gcd 函数中。这是我的代码。

#include<stdio.h>
#include<conio.h>
int main(void)

int gcd(int,int);
{
int a,b, temp;
printf("Enter the value of a");
scanf("%d",&a);
printf("Enter the value of b");
scanf("%d",&b);
if (b>=a)
{
int temp;
temp=b;
b=a;
a=temp;

}
elseif(b!=0)
{
gcd(a,b);
printf("The Gcd of the numbere is %d",gcd(a,b));
}
else
{
printf("The GCD of %d %d is %d:",a,b,a);
}
getch();

return 0;
}

int gcd(int a,int b)
{
int g;
while(b!=0)
{
g=a%b;
a=b;
b=g;
return g;
}

}

如果您指出我的错误并用正确的代码进行解释,我将不胜感激。

最佳答案

交换这两行的位置:

int main(void)

int gcd(int,int);

另外,elseif -> else if

关于c - C语言中使用Function计算GCD时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45255764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com