i ve done so far this code but it deals only with 1 digit numbers i dont know how to make it work for 2 or more digited no.s using atoi or atof functions
#include"stdio. h"
#include"stdlib .h"
#include"string .h"
char postfix[100];
int stack[100];
int top=-1;
void push(int x)
{
top++;
stack[top]=x;
}
int pop()
{
return stack[top--];
}
int evalpost()
{
int a,b,i,temp,resu lt,len;
len=strlen(post fix);
for(i=0;i<len;i ++)
{
if(postfix[i]<='50'&&postf ix[i]>='0')
push(postfix[i]-'0');
else
{
a=pop();
b=pop();
switch(postfix[i])
{
case'+':
temp=a+b;break;
case'-':
temp=b-a;break;
case'*':
temp=a*b;break;
case'/':
temp=b/a;break;
}
push(temp);
}
}
result=pop();
return result;
}
void main()
{
printf("enter rpn\n");
gets(postfix);
top=-1;
int x=evalpost();
printf("%d\n",x );
}
and thanks for ur concern
#include"stdio. h"
#include"stdlib .h"
#include"string .h"
char postfix[100];
int stack[100];
int top=-1;
void push(int x)
{
top++;
stack[top]=x;
}
int pop()
{
return stack[top--];
}
int evalpost()
{
int a,b,i,temp,resu lt,len;
len=strlen(post fix);
for(i=0;i<len;i ++)
{
if(postfix[i]<='50'&&postf ix[i]>='0')
push(postfix[i]-'0');
else
{
a=pop();
b=pop();
switch(postfix[i])
{
case'+':
temp=a+b;break;
case'-':
temp=b-a;break;
case'*':
temp=a*b;break;
case'/':
temp=b/a;break;
}
push(temp);
}
}
result=pop();
return result;
}
void main()
{
printf("enter rpn\n");
gets(postfix);
top=-1;
int x=evalpost();
printf("%d\n",x );
}
and thanks for ur concern
Comment