While trying to do the GCD and LCM program from programming simplified…I am facing problems with the results. I did everything correct(according to me) and even checked word by word but the problem still persists…I am pasting the code of normal method only.
#include <stdio.h>
int main()
{
int a, b, x, y, t, gcd, lcm;
printf("Enter first number :");
scanf("%d", &a);
printf("Enter first number :");
scanf("%d", &b);
a = x;
b = y;
while (b != 0)
{
t = b;
b = a % b;
a = t;
}
gcd = a;
lcm = (x * y)/gcd;
printf("Greatest common divisior of %d and %d = %d\n", x, y, gcd);
printf("Lowest common divisior of %d and %d = %d\n", x, y, lcm);
getch();
}
At least this part is fundamentally wrong:
So you’re declaring
xandyuninitialized, then you’re assigning them toaandb– nowaandbdon’t contain the values the user entered, but some garbage. You probably wantinstead.