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();
   }
}

1 comentários:

Anónimo disse...

I have been exploring for a little bit for any high-quality
articles or blog posts on this kind of house . Exploring in
Yahoo I at last stumbled upon this web site. Studying this information So i'm happy to express that
I have an incredibly excellent uncanny feeling I found out just what I needed.
I most surely will make certain to do not overlook this website and give
it a look on a constant basis.

My homepage: google keyword tool

Enviar um comentário