August 17, 2022 |7.8K Views

    C Program to Determine Whether a Given Number is Even or Odd

    Description
    Discussion

    In this video, we will write a C program to Check Whether an input number is Even or Odd.
    Basically, if a number is divisible by 2 and gives a remainder 0 is known as an EVEN number. Apart from that, Odd numbers are numbers that are not divisible by 2 and give a remainder of 1.

    Algorithm:
    Step 1: Take input of a number from the user.
    Step 2: Divide that number by 2.
    Step 3: If the remainder is 1, then the number is odd.
    Step 4: If the remainder is 0, then the number is Even.
    Step 5: Print result and stop the program.

    In the video, to check whether the number is even or odd we use two different methods:
    1. Using if-else condition
    2. Using Bitwise AND operator

    Examples :
    Input: n = 37
    Output: Odd

    Input: n = 160
    Output: Even

    Apart from that, we will see the time and space complexity of both the methods ,i.e
    Time Complexity: O(1)
    Space Complexity: (1)

    C Program to check whether a given number is even or odd:
    https://www.geeksforgeeks.org/c-program-to-check-whether-a-given-number-is-even-or-odd/