In this example, we are going to find LCM and HCM of two integer.
Output:
Source Code:
#include <stdio.h>
#include <conio.h>
int main()
{
int a, b, x, y, temp,hcm,lcm;
printf("\tProgram to find LCM and HCM of Two Numbers");
printf("\n------------------------------------------------------\n");
printf("Enter Two Numbers : ");
scanf("%d %d", &x, &y);
a = x;
b = y;
//calculate hcm by interchanging position
while(b != 0)
{
temp = b;
b = a % temp;
a = temp;
}
hcm = a;
//calculate lcm
lcm = (x*y)/hcm;
//display hcm and lcm
printf("HCM = %d, LCM = %d",hcm,lcm);
getch();
return 0;
}
#include <stdio.h>
#include <conio.h>
int main()
{
int a, b, x, y, temp,hcm,lcm;
printf("\tProgram to find LCM and HCM of Two Numbers");
printf("\n------------------------------------------------------\n");
printf("Enter Two Numbers : ");
scanf("%d %d", &x, &y);
a = x;
b = y;
//calculate hcm by interchanging position
while(b != 0)
{
temp = b;
b = a % temp;
a = temp;
}
hcm = a;
//calculate lcm
lcm = (x*y)/hcm;
//display hcm and lcm
printf("HCM = %d, LCM = %d",hcm,lcm);
getch();
return 0;
}
Output:
No comments:
Post a Comment