Computer Science, asked by chalotragourav, 1 year ago

write a c program to find odd and even number out of any three number.

Answers

Answered by gsaianimesh
0

C program to check odd or even: We will determine whether a number is odd or even by using different methods all are provided with a C language program. As you have studied in Mathematics that in decimal number system even numbers are divisible by two while odd numbers are not so we can use modulus operator(%) which returns remainder, for example, 4%3 gives 1 (remainder when four is divided by three). Even numbers are of the form 2*n, and odd numbers are of the form (2*n+1) where n is is an integer.

Odd or even program in C using modulus operator

#include <stdio.h>

 

int main()

{

  int n;

   

  printf("Enter an integer\n");

  scanf("%d", &n);

   

  if (n%2 == 0)

     printf("Even\n");

  else

     printf("Odd\n");

     

  return 0;

}

We can use bitwise AND (&) operator to check odd or even, as an example consider binary of 7 (0111) when we perform 7 & 1 the result will be one, and you may observe that the least significant bit of every odd number is 1. Therefore (odd_number & 1) will be one always and also (even_number & 1) is always zero.


chalotragourav: thanks
Similar questions