Balanced Parantheses using Stack C Program

C Program To Check Balanced Parantheses using Stack Data Structure

Learn How To Check Balanced Parantheses using Stack Data Structure in C Programming Language. This C Program checks if Parantheses of an Expression are Balanced or Not using Stack Data Structure. If the parantheses do not match or if the Number is not even, then the expression will have unbalanced parantheses. This C Program checks Nesting of Parantheses in an Expression as well.

The parantheses used in an algebraic expression are: { [ ( and its matching Right parantheses. The Number of Paratheses should, therefore be even or in other words, the opening parantheses should be equivalent to the closing parantheses. For every opening bracket, there should be a similar closing bracket.

Algorithm To Check if Parantheses are Balanced or Not

  • Declare A Stack
  • Input Algebraic Expression from the User
  • Traverse the Expression
    • Push the Current Character to Stack if it is an Opening Parantheses such as (, [ or {.
    • Pop the Current Character from Stack if the Expression has a Closing Bracket such as ), ] or }.
      • If the Popped Character is matching the starting parantheses, then the Expression is Balanced else it includes Unbalanced Parantheses.
  • After Traversal is completed, if there is any remaining Left Bracket in the Stack, then the Parantheses are not Balanced.

Must Read: C Program To Reverse a Stack String

C Program To Check Balanced Parantheses using Stack in an Algebraic Expression


Check Balanced Parantheses using Stack Data Structure in C Programming

If you have any compilation errors or doubts in this Data Structure Program to Find Balanced Parantheses in C Programming, let us know about in the Comment Section below. Find more about Stack and Queues on

Tushar Soni

I am Tushar Soni, Co - Founder of CodingAlpha. I am a computer science student from India and passionate about Web Development and Programming. Connect with me on Facebook | LinkedIn | Google Plus

4 thoughts on “Balanced Parantheses using Stack C Program

  • September 11, 2016 at 11:59 am

    Thanks for the algorithm! This is too good! It has helped me to understand the program code with much ease.

  • September 13, 2016 at 10:30 am

    You have simplified the code for balanced parantheses. I finally could understand the logic now.

  • October 19, 2016 at 12:01 am

    Simple and easy to understand.

  • October 20, 2016 at 9:00 am

    Amazing Parantheses Checker C Program!


Join The Discussion