Hello, I've got this really weird problem.
#include <stdio.h>
int gcf(int a, int b) {
int tmp;
if (a < b) {
tmp = a;
a = b;
b = tmp;
}
if (a % b == 0) {
return b;
}
else {
gcf(b, (a % b));
}
}
int lcm(int a, int b) {
return (a / gcf(a, b)) * b;
}
int main(int argc, char *argv[]) {
int a, b, x, y;
printf("Enter integer 1: ");
scanf("%d", &a);
printf("Enter integer 2: ");
scanf("%d", &b);
x = gcf(a, b);
y = lcm(a, b);
printf("\nGreatest common factor: %d\n", x);
printf("Least common multiple: %d\n", y);
return 0;
}
In Linux, doing gcc -o program program.c works just fine. But I'd also like to compile it for Windows so I tried Code Blocks. A sample input of 12 and 36 works just fine but an input of 18 and 84 gives a result of 2009155360 and 0. :? Any things I should consider? Looking forward to your replies.
Thanks!
Shouldn't it be:
else {
return gcf(b, (a % b));
}
And 18 and 84 returns me 6 and 252, which should be right.
Attention, this has nothing to do with Code::Blocks, please ask this question on a c/c++ forum.
greets GeO