1)if the result is not 0, double the result and use it as the first number and repeat step 1.
For example :
let us consider 7 , 8 as inputs
step 1 :
7 * 2 - 8 = 6, which is not zero, so it goes to next step and first number is 6
6 * 2 - 8 = 4, which is not zero, so it goes to next step and first number is 4
4 * 2 - 8 = 0, here it satisfies the condition so system will print 7 , 8
Another sample set that satisfies the above condition: 10, 20
10 * 2 - 20 = 0, here it satisfies the condition so system will print 10 , 20
And that string must have for every opening parenthesis it must be close with corresponding parenthesis.
Example 1:((hai hello ) all the (best))
It should return true.
Example 2: ())(
It should return false.
Shashank PatilPosted Sep 10, 2015, 12:35 AM
//Inputs: First variable should be less than second variable. If its not then it's false
public void Output(int var1, int var2)
{
if(var1 < var2)
{
bool returnValue = RecursiveOut(var1, var2);
if(returnValue == true)
{
Console.WriteLine("Display Inputs: " + var1 + "," + var2);
}
}
}
public bool RecursiveOut(var1, var2)
{
if(var1 > 0)
{
var1 = var1*2 - var2;
if(var1 == 0)
{
return true;
}
return RecursiveOut(var1, var2);
}
return false;
}
//Program 2
//use stack : push if open brace. Pop if close brace.
//At the end of string the stack should be empty to statisfy the operation
public bool ParseString()
{
string str1 = Console.ReadLine();
Stack stack = new Stack();
if(line != null)
{
foreach(character in str1.ToCharArray())
{
if(character == "(")
{
stack.Push("(");
}
else if(character == ")")
{
stack.Pop();
}
}
if(stack.Count == 0)
{
return true;
}
}
return false;
}
Manas MohapatraPosted Sep 9, 2015, 12:32 PM