❤ 💻 C# / .NET - check if number is odd - Dirask

PHOTO EMBED

Fri Jul 14 2023 17:42:42 GMT+0000 (Coordinated Universal Time)

Saved by @andersoncampos #undefined

using System;

​

public class Program

{

    public static void Main(String[] args)

    {    

        Console.WriteLine( NumberUtils.IsOdd(0) );   // false

        Console.WriteLine( NumberUtils.IsOdd(1) );   // true      // odd

        Console.WriteLine( NumberUtils.IsOdd(2) );   // false

        Console.WriteLine( NumberUtils.IsOdd(3) );   // true      // odd

        Console.WriteLine( NumberUtils.IsOdd(4) );   // false

        Console.WriteLine( NumberUtils.IsOdd(5) );   // true      // odd

​

        Console.WriteLine( NumberUtils.IsOdd(-1) );  // true      // odd

        Console.WriteLine( NumberUtils.IsOdd(-2) );  // false

        Console.WriteLine( NumberUtils.IsOdd(-3) );  // true      // odd

        Console.WriteLine( NumberUtils.IsOdd(-4) );  // false

        Console.WriteLine( NumberUtils.IsOdd(-5) );  // true      // odd

    }

}

​

public class NumberUtils

{

    public static bool IsOdd(int number)

    {

        return (number & 1) != 0;

    }

}
content_copyCOPY

Verificar se número é ímpar

https://dirask.com/posts/C-NET-check-if-number-is-odd-Dl63Ej