J
Joe Smith
[original code snipped]
#include <stdio.h>
int main(void)
{
long unsigned gcd(long unsigned m, long unsigned n);
long unsigned m;
long unsigned n;
long unsigned t;
m = 2520;
n = 154;
t = gcd(m, n);
printf("%lu is gcd\n", t);
return 0;
}
long unsigned gcd(long unsigned m, long unsigned n)
{
if(m < n)
{
long unsigned temp = m;
m = n;
n = temp;
}
if(n > 0)
{
long unsigned r;
do
{
r = m % n;
m = n;
n = r ? r : n;
} while(r > 0);
}
return n;
}
/* end source */
I believe this is correct. After a night's sleep and morningly K&R, I don't
think it's true that gcd is called before being declared. Joe
I usually write "long unsigned" instead of "unsigned long",
to remind me not to make a mistake like that, again.
#include <stdio.h>
int main(void)
{
long unsigned gcd(long unsigned m, long unsigned n);
long unsigned m;
long unsigned n;
long unsigned t;
m = 2520;
n = 154;
t = gcd(m, n);
printf("%lu is gcd\n", t);
return 0;
}
long unsigned gcd(long unsigned m, long unsigned n)
{
if(m < n)
{
long unsigned temp = m;
m = n;
n = temp;
}
if(n > 0)
{
long unsigned r;
do
{
r = m % n;
m = n;
n = r ? r : n;
} while(r > 0);
}
return n;
}
/* end source */
I believe this is correct. After a night's sleep and morningly K&R, I don't
think it's true that gcd is called before being declared. Joe