Programming-for-Output-Problems
October 6, 2023Programming-for-Output-Problems
October 6, 2023Programming-for-Output-Problems
Question 26 |
Consider the following program fragment
if(a > b)
if(b > c)
s1;
else
s2;
s2 will be executed if
if(a > b)
if(b > c)
s1;
else
s2;
s2 will be executed if
a <= b | |
b > c | |
b >= c and a <= b | |
a > b and b <= c |
Question 26 Explanation:
Here, possibility to happen “dangling if” error. But according to else statement it is matched with above if statement only.
We can write code segment is like this because to avoid “dangling if”
if(a>b)
{
if(b>c)
{ s1; }
else
{ s2; }
}
→ To execute s2, it (a>b) should be TRUE. And it (b>c) should be FALSE.
Hence, Option-D is correct
We can write code segment is like this because to avoid “dangling if”
if(a>b)
{
if(b>c)
{ s1; }
else
{ s2; }
}
→ To execute s2, it (a>b) should be TRUE. And it (b>c) should be FALSE.
Hence, Option-D is correct
Correct Answer: D
Question 26 Explanation:
Here, possibility to happen “dangling if” error. But according to else statement it is matched with above if statement only.
We can write code segment is like this because to avoid “dangling if”
if(a>b)
{
if(b>c)
{ s1; }
else
{ s2; }
}
→ To execute s2, it (a>b) should be TRUE. And it (b>c) should be FALSE.
Hence, Option-D is correct
We can write code segment is like this because to avoid “dangling if”
if(a>b)
{
if(b>c)
{ s1; }
else
{ s2; }
}
→ To execute s2, it (a>b) should be TRUE. And it (b>c) should be FALSE.
Hence, Option-D is correct
Subscribe
Login
0 Comments