Jul 14, 2008 at 8:17am UTC
I do not know what I am doing wrong here:
#include <stdio.h>
int gcdlcm(int *a, int *b); //Prototype Variable
void main()
{
int a;
int b;
printf("Enter first number: ");
scanf("%d", &a);
printf("\nEnter second number: ");
scanf("%d", &b);
gcdlcm(&a, &b);
}
int gcdlcm(int *a, int *b)
{
int gcd1 = *a;
int gcd2 = *b;
int lcm1 = *a;
int lcm2 = *b;
while( gcd2 != 0)
{
int m = gcd1 % gcd2;
gcd1 = gcd2;
gcd2 = m;
}
int LCM = ((lcm1 * lcm2) / gcd1);
printf("GCD = %d", gcd1);
printf("LCM = %d", LCM);
return gcd1;
}
Everytime it compiles fine. But when I run it in debug mode(VS2008) it wont print the printf's in the function. Any help would be greatly appreciated.
Jul 14, 2008 at 9:16am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#include <stdio.h>
void gcdlcm(int a, int b); //Prototype Variable
void main()
{
int a;
int b;
printf("Enter first number: " );
scanf("%d" , &a);
printf("\nEnter second number: " );
scanf("%d" , &b);
gcdlcm(a, b);
}
void gcdlcm(int a, int b)
{
int gcd1 = a;
int gcd2 = b;
int lcm1 = a;
int lcm2 = b;
while ( gcd2 != 0)
{
int m = gcd1 % gcd2;
gcd1 = gcd2;
gcd2 = m;
}
int LCM = ((lcm1 * lcm2) / gcd1);
printf("GCD = %d \n" , gcd1);
printf("LCM = %d" , LCM);
}
It works fine for me
Last edited on Jul 14, 2008 at 9:19am UTC
Jul 14, 2008 at 9:32am UTC
I'm not familiar with VS2008 but in VS2005 the printfs come out on a separate command window, not in the IDE. It may seem a bit obvious but are you looking for them in the right place?
Jul 14, 2008 at 1:19pm UTC
Nandor, could you possibly post the output that is given. That would really help alot.
Jul 18, 2008 at 8:58am UTC
Enter the first number:345
Enter the second number:213
GDC=3
LCM=24495
Your mistake was probably at the pointers...You referenced and dereferenced the
Last edited on Jul 18, 2008 at 8:59am UTC