Skip to main content

Posts

Showing posts from September 16, 2017

INFIX TO POSTFIX USING STACK IN C(PARENTHESES).

DOWNLOAD FULL PROGRAME CODING: #include<stdio.h> #include<conio.h> #define max 50 char st[max]; int top=-1; void push(char st[],char); char pop(char st[]); void intopostex(char source[],char target[]); int getpriority(char); void main() { char infix[50],postfix[50]; clrscr(); printf("\nENTER INFIX EXPRESSION:\n"); fflush(stdin); gets(infix); strcpy(postfix,""); intopostex(infix,postfix); printf("\nTHE POSTFIX EXPRESSION:\n"); puts(postfix); getch(); } void intopostex(char sourse[],char target[]) { int i=0,j=0; char temp; strcpy(target,""); while(sourse[i]!='\0')  {   if(sourse[i]=='(')    {     push(st,sourse[i]);     i++;    }   else if(sourse[i]==')')    {     while((top!=-1) && (st[top]!='('))     {      target[j]=pop(st);      j++;     }     if(top==-1)     {      printf("\nINCORRECT EXPRESSION..");      exit(1);     }     temp=pop

EVALUATION OF POSTFIX EXPRESSION USING STACK IN C PROGRAM

DOWNLOAD FULL PROGRAME CODING: #include<stdio.h> #include<conio.h> #define max 50 float st[max]; int top=-1; void  push(float st[],float num); float pop(float st[]); float postex(char exp[]); void main() { float num; char exp[50]; clrscr(); printf("ENTER THE POSTFIX EXPRESSION:\n"); fflush(stdin); gets(exp); num=postex(exp); printf("\nANSWER OF THE POSTFIX EXPRESSION:%f",num); getch(); } float postex(char exp[]) { int i=0; float no1,no2,num; while(exp[i]!='\0') {  if(isdigit(exp[i]))    push(st,(float)(exp[i]-'0'));  else  {   no1=pop(st);   no2=pop(st);  switch(exp[i])   {    case '+':    num=no1+no2;    break;    case '-':    num=no1-no2;    break;    case '*':    num=no1*no2;    break;    case '/':    num=no1/no2;    break;    case '%':    num=(int)no1%(int)no2;    break;    }     push(st,num);   }    i++;  }   return (pop(st)); } void