Program 5CUDA 1 Parentheses Matching Due Tues 11292016 Write
Solution
paranthesis.cu
#include < stdio.h >
#define max 50
void main()
{
//declaring variables
char stack[max],input[100];
int top,i;
top = -1;
printf(\"\ Enter expression: \");
gets(input);
// processing each char
for(i=0; input[i] != \'\\0\'; i++)
{
if( input[i]==\'(\' || input[i] ==\'[\' || input[i] == \'{\' )
{
top++;
stack[top]= input[i];
}
else
if ( input[i] == \')\' )
{
if( stack[top] == \'(\' )
top--;
}
else
{
printf(\"wrong Paranthesis input\");
exit(0);
}
}
else
if ( input[i] == \']\' )
{
if( stack[top] == \'[\' )
top--;
else
{
printf(\"wrong Paranthesis input\");
exit(0);
}
}
else
if ( input[i] == \'}\' )
{
if( stack[top] == \'{\' )
top--;
else
{
printf(\"wrong Paranthesis input\");
exit(0);
}
}
} // end for
if( top == -1 )
printf(\"Youe entered expression is balanced one. Good job!!\");
else
printf(\"Youe entered expression is not balanced one. Try again!!\");
}

