#include<stdio.h>
#include<conio.h>
int ack(int,int);
int main()
{
int m,n;
printf("Enter value M: ");
scanf("%d",&m);
printf("Enter value N: ");
scanf("%d",&n);
if(n<0||m<0)
printf("Ackermann function not defined....");
else
printf("Ack(%d,%d)= %d",m,n,ack(m,n));
getch();
return 0;
}
int ack(int m,int n)
{
if(m==0 && n>=0)
return (n+1);
else if(m>0 && n==0)
return ack(m-1,1);
else if(m>0 && n>0)
return (ack(m-1,ack(m,n-1)));
return 0;
}
#include<conio.h>
int ack(int,int);
int main()
{
int m,n;
printf("Enter value M: ");
scanf("%d",&m);
printf("Enter value N: ");
scanf("%d",&n);
if(n<0||m<0)
printf("Ackermann function not defined....");
else
printf("Ack(%d,%d)= %d",m,n,ack(m,n));
getch();
return 0;
}
int ack(int m,int n)
{
if(m==0 && n>=0)
return (n+1);
else if(m>0 && n==0)
return ack(m-1,1);
else if(m>0 && n>0)
return (ack(m-1,ack(m,n-1)));
return 0;
}
No comments:
Post a Comment
Convey your thoughts to authors.