#include<stdio.h>
#include<conio.h>
#define MAX 50
struct stack
{
int a[MAX];
}s1;
int top=-1,i;
char s[MAX];
void main()
{
clrscr();
printf("\nEnter the expression:");
scanf("%s",&s);
for(i=0;s[i]!='\0';i++)
{
if(s[i]=='(')
{
top=top+1 ;
s1.a[top]=s[i];
}
else if(s[i]==')')
{
top=top-1;
}}
if(top==-1)
printf("\nBalanced Paranthesis");
else
printf("\nUnbalanced Paranthesis");
getch();
}
No comments:
Post a Comment