#include <stdio.h>
int main(void)
{
int x,y,gcd,lcm,i,j,temp;
printf("enter 2 numbers(no less than 1):\n");
scanf("%d %d",&x,&y);
do{
printf("What do you want? 1.gcd, 2.lcm\n");
scanf("%d",&i);
} while(i<1||i>2);
if(i==1)
{
if(x>=y){
for(j=1;j<=y;j++){
if((x%j==0)&&(y%j==0)) temp=j;
}
printf("%d is gcd of %d and %d.\n",temp,x,y);
}
if(y>=x){
for(j=1;j<=x;j++){
if((y%j==0)&&(x%j==0)) temp=j;
}
printf("%d is gcd of %d and %d.\n",temp,x,y); }
}
if(i==2)
{
if(x>=y){
for(j=x;;j++){
if((j%x==0)&&(j%y==0)) {printf("%d is lcm of %d and %d.\n",j,x,y);break;}}
}
if(y>=x){
for(j=y;;j++){
if((j%x==0)&&(j%y==0)) {printf("%d is lcm of %d and %d.\n",j,x,y);break;}}
}
}
return 0;
} |