adplus-dvertising
frame-decoration

Question

Select the correct ‘if statement’ to be filled in the given set of code :
static void Main(string[] args)
 {
     int []num = {50, 65, 56, 88, 43, 52};
     int even = 0, odd = 0;
     for (int i = 0 ;i < num.Length ;i++)
     {
          /*___________________________*/
     }   
     Console.WriteLine("Even Numbers:" +even);
     Console.WriteLine("Odd Numbers:" +odd);
     Console.ReadLine();
 }

a)

if ((num % 2) == 0)
   {
       even += 1;
   }
   else
   {
       odd += 1;
   }

b)

 if((num * i) == 0)
   {
       even += 1;
   }
   else
   {
       odd += 1;
   }

c)

if(num[i] % 2 == 0)
    {
        even += 1;
    }
    else
    {
        odd += 1;
    }

d)

 if(num[i] % 2 = 0)
    {
        even += 1;
    }
    else
    {
        odd += 1;
    }

a.

a

b.

b

c.

c

d.

d

Posted under C# programming

Answer: (c).c

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. Select the correct ‘if statement’ to be filled in the given set of code :