Problem Statement:- Program to check whether a number is even or odd using bitwise operator.
Sample Input/Output:-
Data requirement:-
Input Data:- number
Output Data:-String Output
Program in C
Here is the source code of the C Program to check whether a number is even or odd using the bitwise operator.
Code:
#include <stdio.h>int main(){ int number; /* Get the number input */ printf("Enter the Number:"); scanf("%d",&number); /* Checking the given number is odd or even using bitwise operators.*/ if (number & 1)/* or if(number&1==1)*/ printf("%d is an Odd Number.\n", number); else printf("%d is an Even Number.\n", number); return 0;}
Input/Output:
Enter the Number:17
17 is an Odd Number.
#include <stdio.h>int main(){ int number; /* Get the number input */ printf("Enter the Number:"); scanf("%d",&number); /* Checking the given number is odd or even using bitwise operators.*/ if (number & 1)/* or if(number&1==1)*/ printf("%d is an Odd Number.\n", number); else printf("%d is an Even Number.\n", number); return 0;}
Program in C++
Here is the source code of the C++ Program to check whether a number is even or odd using the bitwise operator.
Code:
#include <iostream>using namespace std;int main(){ int number; /* Get the number input */ cout<<"Enter the Number:"; cin>>number; /* Checking the given number is odd or even using bitwise operators.*/ if (number & 1)/* or if(number&1==1)*/ cout<<number<<" is an Odd Number."; else cout<<number<<" is an Even Number."; return 0;}
#include <iostream>using namespace std;int main(){ int number; /* Get the number input */ cout<<"Enter the Number:"; cin>>number; /* Checking the given number is odd or even using bitwise operators.*/ if (number & 1)/* or if(number&1==1)*/ cout<<number<<" is an Odd Number."; else cout<<number<<" is an Even Number."; return 0;}
Input/Output:
Enter the Number:8
8 is an Even Number.
Program in Java
Here is the source code of the Java Program to check whether a number is even or odd using the bitwise operator.
Code:
import java.util.Scanner;
public class CheckOddEvenNumber { public static void main(String[] args) { Scanner cs = new Scanner(System.in); /* Get the number input */ System.out.print("Enter the Number:"); int number = cs.nextInt(); /* * Checking the given number is odd or even using bitwise operators. */ if ((number & 1) == 1) System.out.print(number + " is an Odd Number."); else System.out.print(number + " is an Even Number."); cs.close(); }}
Input/Output:
Enter the Number:37
37 is an Odd Number.
import java.util.Scanner;
public class CheckOddEvenNumber { public static void main(String[] args) { Scanner cs = new Scanner(System.in); /* Get the number input */ System.out.print("Enter the Number:"); int number = cs.nextInt(); /* * Checking the given number is odd or even using bitwise operators. */ if ((number & 1) == 1) System.out.print(number + " is an Odd Number."); else System.out.print(number + " is an Even Number."); cs.close(); }}
Program in Python
Here is the source code of the Python Program to check whether a number is even or odd using the bitwise operator.
Code:
# Get the number inputnumber = int(input("Enter the Number:"))# Checking the given number is odd or even using bitwise operators.if (number & 1): #or if(number&1==1) print(number," is an Odd Number.")else: print(number," is an Even Number.")
Input/Output:
Enter the Number:778
778 is an Even Number.
# Get the number inputnumber = int(input("Enter the Number:"))# Checking the given number is odd or even using bitwise operators.if (number & 1): #or if(number&1==1) print(number," is an Odd Number.")else: print(number," is an Even Number.")
0 Comments
Please do not Enter any spam link in the comment box