Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
Lab 6

Lab 6

Ratings: (0)|Views: 8 |Likes:
Published by Sandeep V Gowda
Data Structures Lab Program 6, VTU
Data Structures Lab Program 6, VTU

More info:

Published by: Sandeep V Gowda on Nov 12, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as RTF, PDF, TXT or read online from Scribd
See more
See less

03/12/2014

pdf

text

original

 
6.Write a C Program to evaluate a valid suffix/postfix expressionusing stack. Assume that the suffix/postfix expression is read asa single line consisting of non-negative single digit operands andbinary arithmetic operators. The arithmetic operators are +(add),-(subtract), *(multiply) and /(divide).PROGRAM
#include<stdio.h>#include<string.h>#include<conio.h>#include<math.h>#include<ctype.h>float cal(float op1,char ch,float op2){switch(ch){case '+': return (op1+op2);case '-': return (op1-op2);case '*': return (op1*op2);case '/': return (op1/op2);case '^': return (pow(op1,op2));}}void main(){float s[100],res,op1,op2;int i,top=-1;char pos[100],sym;clrscr();printf("\nEnter the postfix expression..\n");scanf("%s",pos);for(i=0;i<strlen(pos);i++){sym=pos[i];if(isdigit(sym)){s[++top]=sym-'0';}else{op2=s[top--];op1=s[top--];res=cal(op1,sym,op2);s[++top]=res;}}res=s[top--];printf("\n%s = %f",pos,res);getch();}
OUTPUT

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->