#include
int a,b,c,m,n,l,k,num; /*Declaration of variables*/
int recursion(int m,int n); /*Fuunction declaration*/
int GCD(int l,int k); /*Fuunction declaration*/
main()
{
int choice,g1; /*Declaration of variables*/
printf("\nEnter the value of a and b:\n");
printf("a=");
scanf("%d",&a);
printf("b=");
scanf("%d",&b);
printf("\nEnter your choice:\t");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("\ncalling of recyoursive ():\n");
num=recursion(a,b);
printf("The recursive value is:%d",num);
break;
case 2: printf("Calling of GCD function:\n");
g1=GCD(a,b);
printf("%d",g1);
break;
default: printf("Wrong choice");
}
}
int recursion(int m,int n) /*Function definition*/
{
int count;
for(count=1;count
m=(m*a);
}
return m;
}
int GCD(int l,int k) /*Function definition*/
{
int c=0;
int g=0;
c=k%l;
printf("c=%d",c);
if((c==0)&&(l
g=l;
printf("\ngcd=");
}
else
GCD(c,l);
return g;
}
OUTPUT
Enter the value of a and b:
a=2
b=8
Enter your choice: 2
Calling of GCD function:
c=0
gcd=2
No comments:
Post a Comment