(1):
#include
int hcf(int a,int b){
int c=(a<=b)?a:b;
int d=(a>b)?a:b;
int m;
for(int i=1;i<=a;i++){
if(a%i==0&&b%i==0)m=i;
}
return m;
}
int lcd(int a,int b,int m){
return a*b/m;
}
int main(){
int a,b;
printf("Please input an integer:");
scanf("%d",&a);
printf("Please input an integer:");
scanf("%d",&b);
int m=hcf(a,b);
int M=lcd(a,b,m);
printf("hcf:%d\nlcd:%d\n",m,M);
system("pause");
return 0;
}
(2):
#include
int m,M;
void hcf(int a,int b){
int c=(a<=b)?a:b;
int d=(a>b)?a:b;
for(int i=1;i<=a;i++){
if(a%i==0&&b%i==0)m=i;
}
return;
}
void lcd(int a,int b){
M=a*b/m;
return;
}
int main(){
int a,b;
printf("Please input an integer:");
scanf("%d",&a);
printf("Please input an integer:");
scanf("%d",&b);
hcf(a,b);
lcd(a,b);
printf("hcf:%d\nlcd:%d\n",m,M);
system("pause");
return 0;
}
#include
int main()
{
int m,n,t,i;
scanf("%d%d",&m,&n);
if(m>n)
{
t=n;
n=m;
m=t;
}
for(i=m;i>=2;i--)
if(m%i==0&&n%i==0)
printf("%d,%d\n",i,m*n/i);
return 0;
}
这和c语言没什么关系