1 solutions

  • 0
    @ 2025-11-5 15:14:45

    C :

    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
        int a,b,m,q,w;
        scanf("%d%d",&a,&b);
        q=a;
        w=b;
    
        if(a>b)
        {
           m=b;
           b=a;
           a=m;
        }
        while(a)
        {
            m=b%a;
            b=a;
            a=m;    
        }
        printf("%d %d\n",b,q*w/b);
        
    
      return 0;
    }
    
    
    
    
    
    
    
    
    
    

    C++ :

    #include<iostream>
    using namespace std;
    int main()
    {
    	int m,n;
    	cin>>m>>n;
    	int r=m%n,t=m*n;
    	while (r)	//辗转相除法
    	{
    		m=n;
    		n=r;
    		r=m%n;
    	}
    	cout<<n<<" "<<t/n<<endl;
    	return 0;
    }
    
    • 1

    C语言程序设计教程(第三版)课后习题6.1

    Information

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