首页 > 电脑

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

更新时间2020-12-30 05:52:41

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排位赛弹出(账号数据异常即将关闭客户端)?

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