K
whats wrong in this code?? My teacher says logic I have used is wrong
#include<iostream>
using namespace std;
int gcd(int a, int b)
{
int t;
while(b!=0)
{
t = b;
b = a%b; // B's now the remainder of A/B.
a = t;
} // And we go to the next iteration.
return a;
}
int main()
{
int a,b,c,g;
cout<<"Enter 3 numbers: ";
cin>>a>>b>>c;
[B]g=gcd(gcd(a,b),c);[/B] // Comm./Asso. laws...
cout<<"The GCD of the 3 numbers is: "<<g<<endl;
return 0;
}
bigbang@pysnakums:~$ time ./yours
GCD is
6060606
real 0m0.[B]271s[/B]
user 0m0.272s
sys 0m0.000s
bigbang@pysnakums:~$ time ./euclid
The GCD of the 3 numbers is: 6060606
real 0m0.[B]003s[/B]
user 0m0.004s
sys 0m0.000s