Can someone show me how I trace these statements and show changes that were made to each location. I have an example of one problem
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int a, b, c;
a = 5;
b = 10;
c = -15;
if ( ( a + 20 ) > b )
{
cout<< "line 1\n";
a = b + c;
if ( ( a + 25 ) > b )
cout<< "line 2\n";
}
else
cout<< "line 3\n";
int a, b, c;
a = 5;
b = 10;
c = -15;
if ( ( a + 20 ) > b ) //true so line 1 is printed.
{
cout<< "line 1\n";
a = b + c; //changing the value of a to -5
if ( ( a + 25 ) > b ) //true so line 2 is printed
cout<< "line 2\n";
}
else // else part is not executed as if part is already being executed.
cout<< "line 3\n";
OR
1 2 3 4 5 6 7 8 9 10 11 12 13
int a, b, c;
a = 5;
b = 10;
c = -15;
if(( a + 20 ) > b )
{ cout<< "line 1\n";
a = b + c;
if( ( a + 25 ) > b )
{cout<< "line 2\n";}
}
else
cout<< "line 3\n";
Large if else are main.
small if condition is under main if.
So suppose the main if was not executed(if a+20 <=20) then the only output had been