Dain1234 / Design-and-analysis-algorithm

0 stars 0 forks source link

Lcm and Gcd #26

Open Dain1234 opened 2 years ago

Dain1234 commented 2 years ago

include

int main() { int n1,n2,max,i,gcd; printf("enter the two positive integers:\n"); scanf("%d%d",&n1,&n2);

max=(n1>n2) ? n1:n2;

while(1) { if(max%n1==0 && max%n2==0) { printf("lcm of %d and %d is %d\n",n1,n2,max); break; } max++; } for(i=1; i<=n1 && i<=n2; i++) { if(n1%i==0 && n2%i==0) { gcd=i; } } printf("gcd of %d and %d is %d\n",n1,n2,gcd); }