What will be the output of the following C# code? [code] static void Main(string[] args) { int i, j; for (i = 1; i <= 3; i++)

Ngô Quốc Huy

New member
What will be the output of the following C# code?
Code:
 static void Main(string[] args)
 {
     int i, j;
     for (i = 1; i <= 3; i++)
     {
         j = 1;
         while (i % j == 2)
         {
             j++;
         }
         Console.WriteLine(i + " " + j);
     }
     Console.ReadLine();
 }
A. 11 21 31
B. 1 12 13 1
C. 11 21 31
D. 1 1 2 1 3 1
 
Answer: c
Explanation: Since, condition never satisfied for any value of i and j for which (i % j == 2). Hence, j is always constant '1' and 'i' increments for i = 1, 2, 3.
Output:
Code:
 11 21 31.
 

Tìm kiếm

Back
Top