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

 时间:2026-02-13 03:41:33

1、新建项目 01

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

2、新建文件

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

3、写入代码

#include <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程序设计系列-最大公约数

  • 深入理解do-while循环语句的用法
  • 如何编写Helloworld C语言版
  • 取模运算怎么算
  • 最大公约数怎么求
  • gets函数的用法
  • 热门搜索
    大连旅游中专 西安自由行旅游攻略 重庆仙女山旅游攻略 世界旅游胜地排行榜 国际旅游小姐大赛 北京有哪些旅游景点 欢途旅游网 重庆旅游大巴租赁 凉山旅游景点大全 澳门旅游攻略自由行