//Calculation
of HCF and LCM
#include <stdio.h>
#include <conio.h>
long HCF(long, long); //Function Declaration the 2 parameters
void main()
{
long x, y, H, L;
clrscr();
printf("Enter two integers\n");
scanf("%ld%ld", &x, &y);
H = HCF(x, y);
L = (x*y)/H;
printf("HCF of %ld and %ld =
%ld\n", x, y, H);
printf("LCM of %ld and %ld =
%ld\n", x, y, L);
getch();
}
//Body of the function HCF
long HCF(long a, long b)
{
if (b == 0)
{
return a;
}
else
{
return HCF(b, a % b);
}
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.