سؤال بسيط ع #c


(system) #1

مرحبا…
بليز ساعدوني … انا لسه مبتدأ في السي شارب وما بعرف كتير فيها
والمحاضر اعطانا هالسؤال وما عرفت شو بده ولا عرفت احله
ف بليز الي بيعرف يحله ضروري يساعدني…

13 (Dangling-Else Problem) Determine the output for each of the following,
when x is 9 and y is 11 and when x is 11 and y is 9. Note that the compiler ignores the indentation in a C# program.
Also, the C# compiler always associates an else with the previous if unless told to do otherwise
by the placement of braces ({}). On first glance, the programmer may not be sure which if and
else match; this is referred to as the “dangling-else” problem. We have eliminated the indentation
from the following code to make the problem more challenging. (Hint: Apply indentation conventions
that you have learned.)
a) if ( x < 10 )
if ( y > 10 )
Console.WriteLine( “*****” );
else
Console.WriteLine( “#####” );
Console.WriteLine( “$$$$$” );
b) if ( x < 10 ) {
if ( y > 10 )
Console.WriteLine( “*****” );
}
else {
Console.WriteLine( “#####” );
Console.WriteLine( “$$$$$” );

}

(system) #2

when x is 9 and y is 11 the output is :

(a)


$$$$$

(b)


===========================================

when x is 11 and y is 9 the output is :

(a)
$$$$$

(b)

$$$$$