Question

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();
}
Was it helpful?

Solution

int a;

...

scanf("%d",a);

This function call is incorrect C code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top