C++编写程序,求出两个整数的最大公约数和最小公倍数 - 爱问答

(爱问答)

C++编写程序,求出两个整数的最大公约数和最小公倍数

#include<stdio.h>

main()

{

int a,b,x,y;

printf("please enter two positive integer number: ");

scanf("%d,%d",&a,&b);

x=f1(a,b);

printf("the greatest common factor is:%d ",x);

y=f2(a,b);

printf("the lease common multiple is:%d ",y);

}

 

int f1(int a,int b)

{

int t,r;

if(b>a) {t=a;a=b;b=t;}

r=a%b;

while(r!=0)

{

a=b;

b=r

r=a%b;

}

return(b);

}

int f2(int a,int b)

{

int i;

    for (i=1;i<=b;i++)

     if(i*a%b==0)

      return(i*a);

}

 

编译的时候说f1  f2  undeclared identifier

怎么回事,求大神答疑

C++函数必须先声明,后使用的

你要么将你的f1,f2两个函数(整个)移到main的前面

要么在main()前面加

int f1(int a,int b);

int f2(int a,int b);

另外,C++ main的标准写法为

int main(void)


下一篇:有关Python的代码的问题

上一篇:dcvc++中为什么map没有自动补全,vector有自动补全?

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?