VC++6.0程序设计系列-最大公约数

2025-04-18 22:00:27

1、新建项目 01

VC++6.0程序设计系列-最大公约数

2、新建文件

VC++6.0程序设计系列-最大公约数

3、写入代码#inclu蟠校盯昂de <iostream>using namespace std ;//方刮茕栓双法1int gcd1(int a,int b){ int MIN = a>b?b:a ; int res = 1 ; for(int i=2 ;i <= MIN ;i++) { if(a%i==0&&b%i==0)res = i ; } return res ;}//方法2int gcd2(int a,int b){ while(b){ int t = b ; b=a%b ; a=t ; } return a ;}//方法3int gcd3(int a,int b){ return b?gcd3(b,a%b):a ;}int main(){ int a = 24 ; int b = 48 ; cout<<gcd1(a,b)<<endl ; cout<<gcd2(a,b)<<endl ; cout<<gcd3(a,b)<<endl ; return 0 ;}

VC++6.0程序设计系列-最大公约数

4、程序

VC++6.0程序设计系列-最大公约数
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
相关推荐
  • 阅读量:94
  • 阅读量:60
  • 阅读量:46
  • 阅读量:85
  • 阅读量:59
  • 猜你喜欢