8 个解决方案
#1
#include<stdio.h>
int main(){
int m,n,min,i,t;
scanf("%d%d",&m,&n);
min=(m<n)?m:n;
for(i=min;i>=1;i--)
if(m%i==0&&n%i==0){t=i;break;};
printf("最大公约数是:%d",t);
printf("最小公倍数是:%d\n",m*n/t);
return 0;
}
int main(){
int m,n,min,i,t;
scanf("%d%d",&m,&n);
min=(m<n)?m:n;
for(i=min;i>=1;i--)
if(m%i==0&&n%i==0){t=i;break;};
printf("最大公约数是:%d",t);
printf("最小公倍数是:%d\n",m*n/t);
return 0;
}
#2
#include <stdio.h>
04
05 int hcf(int a,int b)
06 {
07 int r=0;
08 while(b!=0)
09 {
10 r=a%b;
11 a=b;
12 b=r;
13 }
14 return(a);
15 }
16
17 lcd(int u,int v,int h)
18 {
19 return(u*v/h);
20 }
21
22 main()
23 {
24 int u,v,h,l;
25 scanf("%d%d",&u,&v);
26 h=hcf(u,v);
27 printf("H.C.F=%d\n",h);
28 l=lcd(u,v,h);
29 printf("L.C.D=%d\n",l);
30 }
04
05 int hcf(int a,int b)
06 {
07 int r=0;
08 while(b!=0)
09 {
10 r=a%b;
11 a=b;
12 b=r;
13 }
14 return(a);
15 }
16
17 lcd(int u,int v,int h)
18 {
19 return(u*v/h);
20 }
21
22 main()
23 {
24 int u,v,h,l;
25 scanf("%d%d",&u,&v);
26 h=hcf(u,v);
27 printf("H.C.F=%d\n",h);
28 l=lcd(u,v,h);
29 printf("L.C.D=%d\n",l);
30 }
#3
从网上搜一下:辗转相除法求最大公约数。上面都有详细介绍。
#4
/* 最大公约数 */
#include <stdio.h>
int gdc(int a,int b);
main()
{
int a,b,r;
printf("please enter nubmer 1\n");
scanf("%d",&a);
printf("please enter number 2\n");
scanf("%d",&b);
printf("a is %d ,b is %d\n",a,b);
printf("the result of common divisor is %d\n",gdc(a,b));
}
int gdc(int a,int b)
{
int r;
while (1==1)
{
r = a % b;
if (r == 0)
break;
a = b;
b = r;
}
return b;
}
#include <stdio.h>
int gdc(int a,int b);
main()
{
int a,b,r;
printf("please enter nubmer 1\n");
scanf("%d",&a);
printf("please enter number 2\n");
scanf("%d",&b);
printf("a is %d ,b is %d\n",a,b);
printf("the result of common divisor is %d\n",gdc(a,b));
}
int gdc(int a,int b)
{
int r;
while (1==1)
{
r = a % b;
if (r == 0)
break;
a = b;
b = r;
}
return b;
}
#5
/* 最小公倍数 */
#include <stdio.h>
int multiple(int a,int b);
main()
{
int a,b;
printf("please enter nubmer 1\n");
scanf("%d",&a);
printf("please enter number 2\n");
scanf("%d",&b);
printf("a is %d ,b is %d\n",a,b);
printf("the result of common multiple is %d\n",multiple(a,b));
}
int multiple(int a,int b)
{
int n = 1;
int result;
while (1==1)
{
result = a * n++;
if ( (result%b) == 0)
{
break;
}
}
return result;
}
#include <stdio.h>
int multiple(int a,int b);
main()
{
int a,b;
printf("please enter nubmer 1\n");
scanf("%d",&a);
printf("please enter number 2\n");
scanf("%d",&b);
printf("a is %d ,b is %d\n",a,b);
printf("the result of common multiple is %d\n",multiple(a,b));
}
int multiple(int a,int b)
{
int n = 1;
int result;
while (1==1)
{
result = a * n++;
if ( (result%b) == 0)
{
break;
}
}
return result;
}
#6
#include<stdio.h>
void main()
{
int max_(int a,int b); //调用最大公约数函数的声明
int min_(int a,int b); //调用最小公倍数的函数声明
int m,n,max,min;
printf("请输入两个数");
scanf("%d%d",&m,&n);
max=max_(m,n); //调用最大公约数
printf("%d和%d的最大公约数是%d\n",m,n,max);
min=min_(m,n); //调用最小公倍数
printf("%d和%d的最小公倍数是%d\n",m,n,min);
}
int max_(int a,int b)
{
int t;
t=a>b?b:a;//从两个数中较小的开始
while(a%t!=0||b%t!=0)//倘若该数不能被a、b两数同时整除
t--;//该数自减,直到找到一个数能被a、b同时整除为止
return(t);//将该数作为返回值
}
int min_(int a,int b)//最小公倍数的思想其实和最大公约数的思想是类似的,楼主自己看吧~~~
{
int t;
t=a>b?a:b;
while(t%a!=0||t%b!=0)
t++;
return(t);
}
void main()
{
int max_(int a,int b); //调用最大公约数函数的声明
int min_(int a,int b); //调用最小公倍数的函数声明
int m,n,max,min;
printf("请输入两个数");
scanf("%d%d",&m,&n);
max=max_(m,n); //调用最大公约数
printf("%d和%d的最大公约数是%d\n",m,n,max);
min=min_(m,n); //调用最小公倍数
printf("%d和%d的最小公倍数是%d\n",m,n,min);
}
int max_(int a,int b)
{
int t;
t=a>b?b:a;//从两个数中较小的开始
while(a%t!=0||b%t!=0)//倘若该数不能被a、b两数同时整除
t--;//该数自减,直到找到一个数能被a、b同时整除为止
return(t);//将该数作为返回值
}
int min_(int a,int b)//最小公倍数的思想其实和最大公约数的思想是类似的,楼主自己看吧~~~
{
int t;
t=a>b?a:b;
while(t%a!=0||t%b!=0)
t++;
return(t);
}
#7
看懂了 ,谢谢啊
#8
嘿嘿 俺也是初学者~~~不谢啊……嘿嘿
#1
#include<stdio.h>
int main(){
int m,n,min,i,t;
scanf("%d%d",&m,&n);
min=(m<n)?m:n;
for(i=min;i>=1;i--)
if(m%i==0&&n%i==0){t=i;break;};
printf("最大公约数是:%d",t);
printf("最小公倍数是:%d\n",m*n/t);
return 0;
}
int main(){
int m,n,min,i,t;
scanf("%d%d",&m,&n);
min=(m<n)?m:n;
for(i=min;i>=1;i--)
if(m%i==0&&n%i==0){t=i;break;};
printf("最大公约数是:%d",t);
printf("最小公倍数是:%d\n",m*n/t);
return 0;
}
#2
#include <stdio.h>
04
05 int hcf(int a,int b)
06 {
07 int r=0;
08 while(b!=0)
09 {
10 r=a%b;
11 a=b;
12 b=r;
13 }
14 return(a);
15 }
16
17 lcd(int u,int v,int h)
18 {
19 return(u*v/h);
20 }
21
22 main()
23 {
24 int u,v,h,l;
25 scanf("%d%d",&u,&v);
26 h=hcf(u,v);
27 printf("H.C.F=%d\n",h);
28 l=lcd(u,v,h);
29 printf("L.C.D=%d\n",l);
30 }
04
05 int hcf(int a,int b)
06 {
07 int r=0;
08 while(b!=0)
09 {
10 r=a%b;
11 a=b;
12 b=r;
13 }
14 return(a);
15 }
16
17 lcd(int u,int v,int h)
18 {
19 return(u*v/h);
20 }
21
22 main()
23 {
24 int u,v,h,l;
25 scanf("%d%d",&u,&v);
26 h=hcf(u,v);
27 printf("H.C.F=%d\n",h);
28 l=lcd(u,v,h);
29 printf("L.C.D=%d\n",l);
30 }
#3
从网上搜一下:辗转相除法求最大公约数。上面都有详细介绍。
#4
/* 最大公约数 */
#include <stdio.h>
int gdc(int a,int b);
main()
{
int a,b,r;
printf("please enter nubmer 1\n");
scanf("%d",&a);
printf("please enter number 2\n");
scanf("%d",&b);
printf("a is %d ,b is %d\n",a,b);
printf("the result of common divisor is %d\n",gdc(a,b));
}
int gdc(int a,int b)
{
int r;
while (1==1)
{
r = a % b;
if (r == 0)
break;
a = b;
b = r;
}
return b;
}
#include <stdio.h>
int gdc(int a,int b);
main()
{
int a,b,r;
printf("please enter nubmer 1\n");
scanf("%d",&a);
printf("please enter number 2\n");
scanf("%d",&b);
printf("a is %d ,b is %d\n",a,b);
printf("the result of common divisor is %d\n",gdc(a,b));
}
int gdc(int a,int b)
{
int r;
while (1==1)
{
r = a % b;
if (r == 0)
break;
a = b;
b = r;
}
return b;
}
#5
/* 最小公倍数 */
#include <stdio.h>
int multiple(int a,int b);
main()
{
int a,b;
printf("please enter nubmer 1\n");
scanf("%d",&a);
printf("please enter number 2\n");
scanf("%d",&b);
printf("a is %d ,b is %d\n",a,b);
printf("the result of common multiple is %d\n",multiple(a,b));
}
int multiple(int a,int b)
{
int n = 1;
int result;
while (1==1)
{
result = a * n++;
if ( (result%b) == 0)
{
break;
}
}
return result;
}
#include <stdio.h>
int multiple(int a,int b);
main()
{
int a,b;
printf("please enter nubmer 1\n");
scanf("%d",&a);
printf("please enter number 2\n");
scanf("%d",&b);
printf("a is %d ,b is %d\n",a,b);
printf("the result of common multiple is %d\n",multiple(a,b));
}
int multiple(int a,int b)
{
int n = 1;
int result;
while (1==1)
{
result = a * n++;
if ( (result%b) == 0)
{
break;
}
}
return result;
}
#6
#include<stdio.h>
void main()
{
int max_(int a,int b); //调用最大公约数函数的声明
int min_(int a,int b); //调用最小公倍数的函数声明
int m,n,max,min;
printf("请输入两个数");
scanf("%d%d",&m,&n);
max=max_(m,n); //调用最大公约数
printf("%d和%d的最大公约数是%d\n",m,n,max);
min=min_(m,n); //调用最小公倍数
printf("%d和%d的最小公倍数是%d\n",m,n,min);
}
int max_(int a,int b)
{
int t;
t=a>b?b:a;//从两个数中较小的开始
while(a%t!=0||b%t!=0)//倘若该数不能被a、b两数同时整除
t--;//该数自减,直到找到一个数能被a、b同时整除为止
return(t);//将该数作为返回值
}
int min_(int a,int b)//最小公倍数的思想其实和最大公约数的思想是类似的,楼主自己看吧~~~
{
int t;
t=a>b?a:b;
while(t%a!=0||t%b!=0)
t++;
return(t);
}
void main()
{
int max_(int a,int b); //调用最大公约数函数的声明
int min_(int a,int b); //调用最小公倍数的函数声明
int m,n,max,min;
printf("请输入两个数");
scanf("%d%d",&m,&n);
max=max_(m,n); //调用最大公约数
printf("%d和%d的最大公约数是%d\n",m,n,max);
min=min_(m,n); //调用最小公倍数
printf("%d和%d的最小公倍数是%d\n",m,n,min);
}
int max_(int a,int b)
{
int t;
t=a>b?b:a;//从两个数中较小的开始
while(a%t!=0||b%t!=0)//倘若该数不能被a、b两数同时整除
t--;//该数自减,直到找到一个数能被a、b同时整除为止
return(t);//将该数作为返回值
}
int min_(int a,int b)//最小公倍数的思想其实和最大公约数的思想是类似的,楼主自己看吧~~~
{
int t;
t=a>b?a:b;
while(t%a!=0||t%b!=0)
t++;
return(t);
}
#7
看懂了 ,谢谢啊
#8
嘿嘿 俺也是初学者~~~不谢啊……嘿嘿