#include<stdio.h>//if the least significant bit is 1 the number is odd and 0 the number is evenintcheckOddEven(intn1){return(n1&1);//The & operator does a bitwise and,}intmain(){intn1;printf("\n\n Function : check the number is even or odd:\n");printf("---\n");printf(...
Check whether a number is even or odd.Steven L. Scott
To check whether an integer is even or odd, the remainder is calculated when it is divided by 2 using modulus operator%. If the remainder is zero, that integer is even if not that integer is odd. Example 1: Check Whether Number is Even or Odd using if else #include<iostream>usingname...
Check give number is Even or Odd #include<iostream.h> #include<conio.h> void main() { int no; clrscr(); cout<<"Enter any num: "; cin>>no; if(no%2==0) { cout<<"Even num"; } else { cout<<"Odd num"; } getch(); } Download Code ...
Here's the equivalent code in Java: Check Whether a Number is Even or Odd in Java In the above program, if num is divisible by 2, "even" is returned. Else, "odd" is returned. The returned value is stored in a string variable evenOdd. Then, the result is printed on the screen us...
To check if a number is even or odd, we take the remainder of the division by 2 and verify: Is the remainder 0? Then the number must be even. Is the remainder 1? Then the number must be odd. Let’s apply this concept to our variables: ...
Check Whether a Number Is Even or Odd With the&Operator in Python Another clever way of determining whether a number is even or odd is by using thebitwise AND operator&. As we all know, everything in the computer is stored in the form of 1s and 0s, or binary language in other words...
# Python Program to Check is Number is even or odd using Modulo defcheck_odd_even(num): ifnum %2==0: return"The Given Number is Even Number" else: return"The Given Number is Odd Number" num =3 print(check_odd_even(num))
This program will determine whether or not the integer is divisible by 2. If the number is divisible, it is an even number; otherwise, it is an odd number.Check if a Number Is Odd or Even in JavaWe’ll explore how to verify whether a number is even or odd when it’s user-defined...
In the module window that opens, enter the following VBA code: Sub CheckEvenOrOddNumber() Dim p As Range For Each p In Worksheets("VBA").Range("B5:B12") If IsNumeric(p.Value) Then If p.Value Mod 2 = 0 Then p.Offset(0, 1).Value = "Even" Else p.Offset(0, 1).Value = ...