Now, with the use of arithmetic operators in coding, we are able to easily determine whether a number is even or odd. This functionality allows for more efficient and accurate programming.
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 2 == 0)
printf("%d is even.
", num);
else
printf("%d is odd.
", num);
return 0;
}
#include <iostream>
int main() {
int num;
std::cout << "Enter a number: ";
std::cin >> num;
if (num % 2 == 0)
std::cout << num << " is even." << std::endl;
else
std::cout << num << " is odd." << std::endl;
return 0;
}
num = int(input("Enter a number: "))
if num % 2 == 0:
print(num, "is even.")
else:
print(num, "is odd.")
import java.util.Scanner;
public class EvenOrOdd {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = scanner.nextInt();
if (num % 2 == 0)
System.out.println(num + " is even.");
else
System.out.println(num + " is odd.");
scanner.close();
}
}