Search code examples
csecuritynumber-theory

Euclidean program for finding gcd in c


I want to perform euclidean progran in c but getting incorrect answer.I have prepared following code for finding gcd

#include<stdio.h>
#include<conio.h>
int gcd(int r1,int r2)
{
int r;
r=r1%r2;
while(r>0)
{
return gcd(r2,r);
}
return r2;
}
void main()
{
int a,b,ans;
clrscr();
printf("enter value of a");
scanf("%d",&a);
printf("enter value of b");
scanf("%d",&b);
ans=gcd(a,b);
printf("%d",ans);
getch();
}

Solution

  • int a;
    
    ...
    
    scanf("%d",a);
    

    This function call is incorrect C code.