What will be the output of the following C# code? [code] static void Main(string[] args) { int x; x = Convert.ToInt32(Console.ReadLi

What will be the output of the following C# code?
Code:
 static void Main(string[] args)
 {
     int x;
     x = Convert.ToInt32(Console.ReadLine());
     int c = 1;
     while (c <= x)
     {
         if (c % 2 == 0)
         {
             Console.WriteLine("Execute While " + c + "\t" + "time");
         }
         c++;
     }
     Console.ReadLine();
 }
for x = 8.
A.
Execute while 1 time
Execute while 3 time
Execute while 5 time
Execute while 7 time
B.
Execute while 2 time
Execute while 4 time
Execute while 6 time
Execute while 8 time
C.
Execute while 1 time
Execute while 2 time
Execute while 3 time
Execute while 4 time
Execute while 5 time
Execute while 6 time
Execute while 7 time
D.
Execute while 2 time
Execute while 3 time
Execute while 4 time
Execute while 5 time
 
Answer: b
Explanation: Checks condition if number is divisible by 2 then it will print it even number times as given for x = 8 so, prints between 2 to 8 times Similarly, for x = 5, Execute 2 and 4 time.
OUTPUT:
Code:
        Execute while 2 time.
        Execute while 4 time.
        Execute while 6 time.
        Execute while 8 time.
 

Tìm kiếm

Back
Top