最小公倍数

算法1:

  1. #include<iostream>
  2. using namespace std;
  3. int Lcm(int no1,int no2)
  4. {
  5.     int temp1=no1,temp2=no2;
  6.     int temp;
  7.     while(no2 != 0)
  8.     {
  9.         temp = no2;
  10.         no2 = no1%no2;
  11.         no1 = temp;
  12.     }
  13.     temp=temp1>temp2?temp1:temp2;
  14.     if(no1==temp)
  15.         return temp;
  16.     else return(temp1/no1*temp2);
  17. }
  18. int main()
  19. {
  20.     int n1,n2;
  21.     cout<<"Please cin two number,I will give least common multiple of them!"<<endl;
  22.     cout<<"Plese the NO1:";
  23.     cin>>n1;
  24.     cout<<"Plese the NO2:";
  25.     cin>>n2;
  26.     cout<<"The least common multiple of "<<n1<<" and "<<n2<<" is "<<Lcm(n1,n2)<<endl;
  27.     return 0;
  28. }

 

算法2:有点懒,所以文字叙述了,^_^.在两个数中找出最小的数,然后++,与最大数相乘再除以最小的那个数,如果能整除,一样可以求出结果,就是时间开销比较大点,当然具体还要细化,我只说了大概步骤..

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值