For the incomplete C# program below, which of the C# code fragment will not result in an infinite loop? [code] static void Main(string[]

Giao Linh

New member
For the incomplete C# program below, which of the C# code fragment will not result in an infinite loop?
Code:
 static void Main(string[] args)
 {
     int i = 1234 ,j = 0;
      /*ADD CODE HERE */
     Console.WriteLine(j);
 }
A.
Code:
 do
    {
        j = j + (i % 10);
    }while ((i = i / 10)!= 0);
B.
Code:
do
    {
        j = j + (i % 10);
    }while ((i / 10)!= 0);
C.
Code:
do
    {
        j = j + (i % 10);
    }while ((i % 10)!= 0);
D.
Code:
do
    {
        j = j + (i % 10);
    }while ((i/10 == 0)!= 0);
 
Answer: a
Explanation: None.
Output :
Code:
static void Main(string[] args)
        {
              int i = 1234,j = 0;
              do
              {
                  j = j +( i % 10);
              }while ((i = i / 10)!= 0);
              Console.WriteLine(j);
}
 

Tìm kiếm

Back
Top