Home / C# Programming / Control Instructions - c# :: Discussion

Discussion :: Control Instructions - c#

  1. Which of the following code snippets are the correct way to determine whether a is Odd or Even?

    1.  int a;
       String res; 
       if (a % 2 == 0)   
           res = "Even";  
      else     
           res = "Odd";
    2. int a;
      String res;
      if (a Mod 2 == 0)  
          res = "Even";  
      else 
          res = "Odd";
    3. int a;
      Console.WriteLine(a Mod 2 == 0 ? "Even": "Odd");
    4. int a; 
      String res; 
      a % 2 == 0 ? res = "Even" : res = "Odd"; Console.WriteLine(res);

  2. A.

    1, 3

    B.

    1 Only

    C.

    2, 3

    D.

    4 Only

    E.

    None of these

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    No answer description available for this question.


Be The First To Comment