Algorithm
Program
#include<stdio.h>
void main()
{
int a,b,n,d,r,gcd,lcm;
printf("Enter two numbers\n");
scanf("%d%d",&a,&b);
n=b;
d=a;
r=a%b;
while(r!=0)
{
n=d;
d=r;
r=n%d;
}
gcd=d;
lcm=(a*b)/gcd;
printf("GCD of %d and %d is %d\n",a,b,d);
printf("LCM is %d\n",lcm);
}
1. Start
2. read two numbers a,b
3. set n=b,d=a
4. r=a%b
5. while r!=0
5.1 set n=d,d=r
5.2 r=n%d
6. set gsc=d
7. lcm=(a*b)/gcd
8. display gcd and lcm
9. stop
2. read two numbers a,b
3. set n=b,d=a
4. r=a%b
5. while r!=0
5.1 set n=d,d=r
5.2 r=n%d
6. set gsc=d
7. lcm=(a*b)/gcd
8. display gcd and lcm
9. stop
Program
#include<stdio.h>
void main()
{
int a,b,n,d,r,gcd,lcm;
printf("Enter two numbers\n");
scanf("%d%d",&a,&b);
n=b;
d=a;
r=a%b;
while(r!=0)
{
n=d;
d=r;
r=n%d;
}
gcd=d;
lcm=(a*b)/gcd;
printf("GCD of %d and %d is %d\n",a,b,d);
printf("LCM is %d\n",lcm);
}
It is a prank
ReplyDeleteam glads to very
ReplyDeleteInstead of while can we use if else
ReplyDeleteIn step 6 of the algorithm, it's gcd=d not gsc
ReplyDelete