可以帮我看看这段代码出了什么问题吗 - 爱问答

(爱问答)

可以帮我看看这段代码出了什么问题吗

Description 给定两个正整数,计算这两个数的最小公倍数。
Input:输入包含多组测试数据,每组只有一行,包括两个不大于1000的正整数.
Output:对于每个测试用例,给出这两个数的最小公倍数,每个实例输出一行。 
 
#include<stdio.h>
int gcd(int a,int b,int temp)
{
  while(b!=0)
  {
   temp=b;
   b=a%b;
   a=temp;
  }
 
}
int lcm(int a,int b, int c)
{
 c=a/gcd(a,b)*b;
}
void main()
{
int temp;
int a,b,c;
while(~scanf("%d%d",&a,&b))
{
 
printf("the minnest common factor of %d and %d is ",a,b);
 
printf("%d ",c);
getchar();
getchar();
}
}

在你程序基础上改好的

#include <stdio.h>
int gcd(int a, int b)
{
   int temp; //临时变量放入函数中定义
   ///网上的公倍数算法都是互相抄的
   ///辗转相除法不用交换大小值的
   while(b != 0)
   {
       temp = a % b;
       a=b;
       b = temp;
   }
   return a;
}
int lcm(int a, int b)
{
   int c; //非指针变量作为参数是不能改变其值的
   c = a / gcd(a, b) * b;
   return c; //所以必须用return返回
}
int main() //ISO C从未有过void main()的写法,也是相互抄的结果
{
 //  int temp;
   int a, b; //, c;
   while(~scanf("%d%d", &a, &b))
   {
       printf("the minnest common factor of %d and %d is ", a,b);
       printf("%d ", lcm(a,b));
      // getchar(); 这里不用也不能有getchar()的
      // getchar();
   }
   getchar(); //可放在这里
   return 0;
}

测试结果(你程序支持多组输入,直到EOF)

可以帮我看看这段代码出了什么问题吗


下一篇:可以帮我看看程序吗

上一篇:CF排位赛弹出(账号数据异常即将关闭客户端)?

热门标签:
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图片查看器怎么没有了?