adplus-dvertising
frame-decoration

Question

For the incomplete program below, which of the code fragment will not result in an infinite loop:
static void Main(string[] args)
 {
     int i = 1234 ,j = 0;
      /*ADD CODE HERE */
     Console.WriteLine(j);
 }

a.

do
{
j = j + (i % 10);
}while ((i = i / 10)!= 0);

b.

do
{
j = j + (i % 10);
}while ((i / 10)!= 0);

c.

do
{
j = j + (i % 10);
}while ((i % 10)!= 0);

d.

do
{
j = j + (i % 10);
}while ((i/10 == 0)!= 0);

Posted under C# programming

Answer: (a).do
{
j = j + (i % 10);
}while ((i = i / 10)!= 0);

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. For the incomplete program below, which of the code fragment will not result in an infinite loop: