Use the mod % operator : Mod « Math « C / ANSI-C






Use the mod % operator

#include <stdio.h>

int main(void)
{
  int i;

  printf("Enter a number: ");
  scanf("%d", &i);
  
  if( ( i % 2 ) == 0) 
      printf("Even");
  if( ( i % 2 ) ==1) 
      printf("Odd");

  return 0;
}

           
       








Related examples in the same category

1.floating-point remainder value function
2.Mod and divide
3. Return remainder of floating point division: fmod Return remainder of floating point division: fmod
4.Split floating-point value into fractional and integer parts: how to use modf