-4

How can I set an if statement for odd and even numbers in c#? I want to set an if condition that if my number is dividing to 2 show that it is even and for else show that it is odd.

I tried to use this operators but it was not true : number !/ 2

at last I wrote this to be able to run the program but I know that it is not true:

using System;

    namespace MyApp // Note: actual namespace depends on the project name.
    {
        internal class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("please enter a number");
                string input = Console.ReadLine();
                int number = Convert.ToInt32(input);
                if (number >= 2)
                {
                    Console.WriteLine("your number is even");
                }
                else
                {
                    Console.WriteLine("your number is odd");
                }
            }
        }
    }
Luuk
  • 12,245
  • 5
  • 22
  • 33

0 Answers0