Originally Posted by
Adak
You have a function gcd which takes two int's - one is the value that you're searching for the gcd of, and the other is a test int?
Hard to say much about it without seeing the code.
Ok...i'll try the assignment in a while...meanwhile...can u advise whether this is correct...thanks
Code:
#include <stdio.h>
void swap (int *X, int *Y);
int gcd (int m, int n);
int main ( )
{
int GCD=0;
int m=0;
int n=0;
scanf("%d",&m);
scanf("%d", &n);
if (n>m)
swap(&m,&n);
GCD=gcd(m,n);
printf("%d", GCD);
return 0;
}
void swap ( int *X, int *Y)
{
int temp;
temp= *X;
*X= *Y;
*Y= temp;
}
int gcd ( int m, int n)
{
return (n==0)? m : gcd(n,m%n) ;
}
are there any instances when this code will fail?
so this operator '? :' is to replace if else?