Dslab Manual
Dslab Manual
s[++top]=postfix[i]-'0';
else
{
op2=s[top--];
op1=s[top--];
switch(postfix[i])
{
case '+':result=op1+op2;
break;
case '-':result=op1-op2;
break;
case '*':result=op1*op2;
break;
case '/':result=op1/op2;
break;
case '%':result=op1%op2;
break;
case '^':result=pow(op1,op2);
break;
}
s[++top]=result;
}
}
printf("\nResult=%d",result);
}
Output:
b. Solving Tower of Hanoi problem with n disks.
#include<stdio.h>
tower(int n, char s, char d, char t)
{
if(n==0)
return;
tower(n-1,s,t,d);
printf("\n Move Disc %d from %c to %c", n,s,d);
tower(n-1,t,d,s);
int main()
{
int n;
printf("\nEnter no of discs\n");
scanf("%d",&n);
tower(n,'A','C','B');
}
Output: