Write an algorithm to check a given number is odd or even.
Answers
Answer:
The algorithm is a step by step representation of program. If the number is divisible by 2, means the remainder is 0 then the number is even.
...
Programming:
//Starting Chat_PC.
#include <stdio.h>
int main()
{
int number;
printf("Enter an integer: ");
scanf("%d", &number);
// True if the number is perfectly divisible by 2.
Explanation:
// Java program program to
// check for even or odd
class GFG
{
// Returns true if n
// is even, else odd
public static boolean isEven(int n)
{
if((n & 1) == 0)
return true;
else
return false;
}
// Driver code
public static void main(String[] args)
{
int n = 101;
if(isEven(n) == true)
System.out.print("Even");
else
System.out.print("Odd");
}
}
// This code is contributed by rishabh_jain
Python3
C#
Output :
Odd