7

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

 1 year ago
source link: https://www.geeksforgeeks.org/videos/c-program-to-determine-whether-a-given-number-is-even-or-odd/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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

C Program to Determine Whether a Given Number is Even or Odd
  • 50 Views
  • 17/08/2022

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/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK