求最大公约数和最小公倍数
#include <stdio.h>
int main()
{
int num_1;
int num_2;
int a = 0;
int b = 0;
int temp = 0;
printf("please input number_1:\n");
scanf("%d",&num_1);
printf("please input number_2:\n");
scanf("%d",&num_2);
if(num_1 < num_2 );
{
temp = num_1;
num_1 = num_2;
num_2 = temp;
}
a = num_1;
b = num_2;
while(b != 0)
{
temp = a % b;
a = b;
b = temp;
}
printf("the GCD is %d\n",a);
printf("the LCM is %d\n",num_1 * num_2 /a);
return 0;
}
求两个分数间大小
#include <stdio.h>
int lcm(int a,int b)
{
int temp;
int c;
c = a * b;
if(a < b)
{
temp = a;
a = b;
b = temp;
}
while(b != 0)
{
temp = a % b;
a = b;
b = temp;
}
return (c / a);
}
int main()
{
int i;
int j;
int k;
int l;
int m;
int n;
printf("please input num_1:\n");
scanf("%d / %d",&i,&j);
printf("please input num_2:\n");
scanf("%d / %d",&k,&l);
m = lcm(j,l) * i / j;
n = lcm(j,l) * k / l;
if(m > n)
{
printf("%d/%d > %d/%d\n",i,j,k,l);
}
else if(m == n)
{
printf("%d/%d = %d/%d\n",i,j,k,l);
}
else if(m < n)
{
printf("%d/%d < %d/%d\n",i,j,k,l);
}
return 0;
}