Check if a number is odd or even in c#

Ver os números primos em c#

static void CheckOddEven(int num)
{
  if (num % 2 == 0)
  { 
    Console.Write("\nYour number is even.\n");
  }  
  else
  {  
    Console.Write("\nYour number is odd.\n"); 
  }
}


static void Main(string[] args)
{ 
  int num = 0;
  string answer = "Y";

  while(answer== "Y")
  {
     Console.Write("Please enter a number and I will tell you whether it is odd or even.\n");

     //convert input to int
     num = int.Parse(Console.ReadLine());

     //call method to check if the number is odd or even
     CheckOddEven(num);

     //ask if the user wants to continue or quit
     Console.Write("Do you wanna check another number? Y/N\n");
    answer= Console.ReadLine().ToUpper();
   }
}

0 comentários:

Enviar um comentário