About

Kannur University btech CSE study materials, question papers, syllabus . . .

Thursday, July 4, 2013

S4 HARDWARE LAB - TASM -CALCULATION OF LCM AND GCD

CALCULATION OF LCM AND GCD
#include <iostream.h>
#include<conio.h>
Int gcd(int x,int y);
Int lcm(int x,int y);
Void main()
{int x,y,r,g,l;
Clrscr();
Printf(“enter the two numbers”);
Scanf(“%d%d”,&x,&y);
g=gcd(x,y);
l=lcm(x,y);
printf(“gcd=%d\nlcm=%d”,g,l);
getch();
}
Int gcd(int  a,int b)
{int r,t,f;
If(a>b)
r=a%b;
else
{f=a;
a=b;
b=f;
r=a%b;
}
While(r>0)
{t=r;
r=b%r;
b=t;
}
return(b);
}
Int lcm(int a,int b)
{int l,g;
g=gcd(a,b);
l=(a*b)/g;
return(l);
}
OUTPUT
Enter the two numbers
36
15
Gcd=3

Lcm=180

0 comments:

Post a Comment