static int Control(int x=0)
string str = "(a(b(c)d)e)";
for (int i = 0; i <= str.Length; i++)
if (str[i] =='(')
if (str[i] == ')')
static void Main(string args)
int x = 0;
bool flag = false;
flag = true;
You were ordered to write two functions, but you have written only one, incorrectly. Also, you did not explain your question properly.—SA
From the very beginning: we are not going to do your homework for your. You are given a change to solve your assignments to learn something. Use this chance well.
Now, in your code there I can see two bugs. First, instead of '<=' you should use '<', in the ending condition of the loop. In the last element, you will get out-of-range exception; there are no elements at the index of
[str.Length] or above.
The second one is the function signature. You don't need
x as a parameter. Declare it locally.
One important practical advice: never ever create single-character names of any entities. How are you going to use "Find" functionality? How can you figure out what do they mean if you read your own code later? All the names should be semantic, maybe, not too long, but self-explaining and even without use of abbreviation: instead of "i" — "index"; instead of "x" — "count", or "balance".
Good luck with recursion version and everything else.
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)