本人是入门者,问一下求最大公约数,一下两种方法,哪里有错误了,?
1》
#include <iostream.h>
void main()
{ long p,q,d;
cout<<"please input two numbers"<<endl;
cin>>p>>q;
cout<<d<<endl;
}
long gcd (long p,long q,long r,long d)
{ r=p%q;
if (p<q)
p>q;
if (r=0)
d=q;
else p=q,q=r;
if (p=q)
d=p=q;
return d;
}
2》#include <iostream.h>
void main()
{ long p,q,d;
cout<<"please input two numbers"<<endl;
cin>>p>>q;
cout<<d<<endl;
}
long gcd (long p,long q,long r,long d)
{ r=p%q;
if (p<q)
p>q;
if (r=0)
d=q;
else p=q,q=r;
if (p=q)
d=p=q;
return d;
}