Ex11-bparenthesis

  • October 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Ex11-bparenthesis as PDF for free.

More details

  • Words: 88
  • Pages: 2
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(); }