#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,no1,no2,i,temp;
cout<<"enter 2 nos";
cin>>a>>b;
no1=a;
no2=b;
while(no2)
{
int temp=no2;
no2=no1%no2;
no1=temp;
}
cout<<"\n GCD="<<no1;
for(i=a; i<=a*b; i++)
{
if(i%a==0 && i%b==0)
{
cout<<"\n LCM="<<i;
break;
}
}
getch();
}
******output******
enter 2 nos 4
6
GCD=2
LCM=12
Algorithm:
1.Read a,b,no1,no2,temp & i.
2.While no2 not equal to zero
a) Set no2=no1/no2 & no1=temp
b) Write G.C.D = no2
3.for initialize integer i=a;i<=a*b;i++
{
if i%a=0 & i%b=0
Write: L.C.M
[End of If structure]
[End of For structure]
4.Exit
1 comments:
Awesome yaar !!!!
Post a Comment