Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- /*03. Write a program to check if in a given expression the brackets are put correctly.
- Example of correct expression: ((a+b)/5-d).
- Example of incorrect expression: )(a+b)). */
- class CorrectBrackets
- {
- static void Main()
- {
- //string text = "((a+b)/5-d)";
- Console.Write("Enter a string: ");
- string text = Console.ReadLine();
- int counter = 0;
- for (int i = 0; i < text.Length; i++)
- {
- if (text[i] == '(')
- {
- counter++;
- }
- else if (text[i] == ')')
- {
- counter--;
- }
- }
- if (counter == 0)
- {
- Console.WriteLine("The brackets are put correctly.");
- }
- else
- {
- Console.WriteLine("The brackets are NOT put correctly.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement