C Program to Check Whether a Number is Even or Odd




c programming
c programming

Write a C Program to find if the number is Odd or Even.
Basically Even numbers are those which are divisible by 2, and Odd number are those which numbers are not divisible 2.

/**
C Program to Check Whether a Number is Even or Odd by codebind.com
*/
#include <stdio.h>
int main()
{
  int number;
  printf("Enter an integer you want to check: ");
  scanf("%d",&number);
  if((number%2)== 0)      /* Checking whether remainder is 0 or not. */
    printf("%d is even.\n", number);
  else
    printf("%d is odd.\n", number);
  return 0;
}


/*
OUTPUT
Enter an integer you want to check: 1203
1203 is odd.
*/

C code to Check if the given number is Even or Odd Using ternary or conditional Operator

/**
C Program to Check Whether a Number is Even or Odd Using ternary or conditional Operator by codebind.com
*/
#include <stdio.h>
int main()
{
  int number;
  printf("Enter an integer you want to check: ");
  scanf("%d",&number);
  (number % 2 == 0) ? printf("%d is even.\n", number) : printf("%d is odd.\n", number);
  return 0;
}


/*
OUTPUT
Enter an integer you want to check: 1203
1203 is odd.
*/

 


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*