adplus-dvertising
frame-decoration

Question

Predict the output for the following set of 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

Posted under C# programming

Answer: (b).Execute while 2 time
Execute while 4 time
Execute while 6 time
Execute while 8 time

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. Predict the output for the following set of code :