1 solutions

  • 0
    @ 2025-11-5 17:33:14

    C :

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    int gcd(int x,int y)
    {
        return y==0?x:gcd(y,x%y);
    }
    int main()
    {
    	int a,b;
        scanf("%d%d",&a,&b);
        printf("%d",gcd(a,b));
    	return 0;
    }
    
    

    C++ :

    #include<cstdio>
    using namespace std;
    
    int gcd(int xx,int yy)
    {
     if(xx==0) return yy;
     else return gcd(yy%xx,xx);
    }
    int main()
    {
        int a,b,t;
        scanf("%d%d",&a,&b);
        
        printf("%d\n",gcd(a,b));
        
        return 0;
    }
    

    Pascal :

    Program ygjngerb;
      var
        a,b:integer;
      function f(a,b:integer):integer;
      var
        i:integer;
      begin
          f:=0;
          for i:=b downto 1 do
          if (a mod i=0) and (b mod i=0) and (i>f) then f:=i;
          if (f=1) then f:=5;
      end;
      begin
        read(a,b);
        write(f(a,b));
      end. 
    
    • 1

    第六章:函数的使用《练习5:求最大公约数gcd》

    Information

    ID
    18552
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By