#include <stdio.h>
#include <stdlib.h>
int m, n;
main( )
{
int x,y;
printf ("Enter two numbers ");
scanf ("%d %d·" , &x, &y);
printf ("RCF of %d and %d is %d\n", x, y, hcf (x, y) );
m=x;n=y;
printf ("LCM of %d and %d is %d\n", x, y, lcm (x, y) );
}
int hcf(int a, int b)
{
if(a==b)
return(b);
else if (a<b)
hcf(a,b-a);
else
hcf(a-b,b);
}
int lcm(int a, int b)
{
if (a==b)
return(b);
else if(a<b)
lcm(a+m,b);
else
lcm(a,b+n);
}
#include <stdlib.h>
int m, n;
main( )
{
int x,y;
printf ("Enter two numbers ");
scanf ("%d %d·" , &x, &y);
printf ("RCF of %d and %d is %d\n", x, y, hcf (x, y) );
m=x;n=y;
printf ("LCM of %d and %d is %d\n", x, y, lcm (x, y) );
}
int hcf(int a, int b)
{
if(a==b)
return(b);
else if (a<b)
hcf(a,b-a);
else
hcf(a-b,b);
}
int lcm(int a, int b)
{
if (a==b)
return(b);
else if(a<b)
lcm(a+m,b);
else
lcm(a,b+n);
}
output:
Enter two numbers 12
15
RCF of 12 and 15 is 3
LCM of 12 and 15 is 60
Enter two numbers 12
15
RCF of 12 and 15 is 3
LCM of 12 and 15 is 60
No comments:
Post a Comment