Pages

Find out Even or Odd integer

Monday 7 January 2013
 Write a program that reads an integer and checks whether it is odd or even.

#include <stdio.h>
#include <conio.h>

int main()
{
   int num = 0;
   int reminder = 0;

   while(num != -1)
   {
      printf("Enter an integer (-1 to stop): ");
      scanf_s("%d", &num, sizeof(int));
    
      if(num != -1)
      {
         reminder = num % 2;
         if(reminder == 0)
             printf("%d is an even number.\n", num);
         else
         printf("%d is an odd number.\n", num);
       }
    }
    printf("%d is an odd number.\n", num);
    printf("You ask to stop! Thank you.\n");
  
    return 0;
}

No comments:

Post a Comment