Ex No: 11 BALANCED PARENTHESIS PROGRAM #include<stdio.h> #include #include<string.h> static int top=0; struct stack { char ex[30]; }st; void create() { for(top=0;top!=20;top++) st.ex[top]=NULL; } void push(char a) { ++top; st.ex[top]=a; } int pop() { if(st.ex[top]==0) { return(0); } else { top=top-1; return(1); } } void main() { char expr[30]; int i,n,err=0,t,m; clrscr(); printf("Enter the expression\n"); scanf("%s",expr); n=strlen(expr); for(i=0;i
{ push(expr[i]); } if(expr[i]==')') { m=pop(); if(m==0) err=1; } } t=pop(); if(t==1||err==1) { printf("The expression is not balanced"); } else { printf("The expression is balanced"); } getch(); }