1、求二个数的最大公约数:

#include <iostream.h>
int maxye(int a,int b)
{
int temp;
while(a%b)
{
  temp=b;
  b=a%b;
  a=temp;
}
return b;
}

void main()
{
int aa,bb;
cout<<"请输入第一个数:";
cin>>aa;
cout<<" 请输入第二个数:";
cin>>bb;
cout<<"这二个数的最大公约数是:"<<maxye(aa,bb)<<endl;
}

 

2、求二个数的最小公倍数

#include <iostream.h>
int maxye(int a,int b)
{
int temp;
if(a<b)
{
  temp=a;
  a=b;
  b=temp;
}
for(int i=1;i<=b;i++)
{
if(!((a*i)%b))
{
  return a*i;
}
}

}

void main()
{
int aa,bb;
cout<<"请输入第一个数:";
cin>>aa;
cout<<" 请输入第二个数:";
cin>>bb;
cout<<"这二个数的最小公倍数是:"<<maxye(aa,bb)<<endl;
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2021-12-20
  • 2021-08-06
  • 2022-02-04
  • 2021-12-19
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2021-09-22
相关资源
相似解决方案