euclids algorithm to find GCD with counter not getting right output
Code:
#include <stdio.h>
int euclid(int a,int b, int c)
{
if(b==0){
c++;
return a;
}
else {
c++;
return euclid(b,a%b, c);
}
}
int main()
{
int n1,n2;
int counter;
printf("Enter two numbers to find its GCD:");
scanf("%d %d",&n1,&n2);
printf("The GCD of %d and %d is %d - counter = %d",n1,n2,euclid(n1,n2, counter),counter);
return 0;
}
Here is my code, when I run it I get this
Enter two numbers to find its GCD:20
5
The GCD of 20 and 5 is 5 - counter = 0