/* C program to find the GCD of two numbers using non recursive functions*/
int gcd(int,int);
main()
{
int a,b;
printf("\n enter any two numbers");
scanf("%d%d",&a,&b);
printf("GCD of %d and %d is %d",a,b,gcd(a,b));
}
int gcd(int c,int d)
{
while(c!=d)
{
if(c>d)
c=c-d;
else if(d>c)
d=d-c;
}
return c;
}
OUTPUT:
enter any two numbers
25 40
GCD of 25 and 40 is 5
/* C program to find the GCD of two numbers using recursive functions*/
int gcd(int,int);
main()
{
int a,b;
printf("\n enter any two numbers");
scanf("%d%d",&a,&b);
printf("GCD of %d and %d is %d",a,b,gcd(a,b));
}
int gcd(int c,int d)
{
if(c>d)
return gcd(c-d,d);
else if(d>c)
return gcd(c,d-c);
else
return c;
}
OUTPUT:
enter any two numbers
25 40
GCD of 25 and 40 is 5
C program to print fibonacci seqeunce using recursive and non recursive functions.
C program to find GCD of two numbers using recursive and non recursive functions, local parameter formal parameters
No comments:
Post a Comment