Table of Contents
In this tutorial, we will discuss the Program to C Check whether the number is odd or even using operators
In this post, we are going to learn how to check whether the given number is odd or even number using operator in C language
Program 1
#include <stdio.h> #include <stdlib.h> int main() { int num;//variable declaration printf("Enter a integer to check odd or even\n"); //the program Asks input from the user scanf("%d",&num); //the integer entered by the user and it is stored in variable num if(num%2==0){ printf("%d is even",num); } else{printf("%d is even",num);} getch(); return 0; }
When the above code is executed ,it produces the following result
case 1
Enter a integer to check odd or even 3500 3500 is even
case 2
Enter a integer to check odd or even 2345 2345 is odd
Program 2
#include <stdio.h> #include <stdlib.h> int main() { int num;//variable declaration printf("Enter a integer to check odd or even\n"); //the program Asks input from the user scanf("%d",&num); //the integer entered by the user and it is stored in variable num if((num/2)*2==num){ printf("%d is even number",num); } else{printf("%d is odd number",num);} getch(); return 0; }
When the above code is executed ,it produces the following result
case 1
Enter a integer to check odd or even 3506 3506 is even number
case 2
Enter a integer to check odd or even 999 999 is odd number
Program 3
#include <stdio.h> #include <stdlib.h> int main() { int num;//variable declaration printf("Enter a integer to check odd or even\n"); //the program Asks input from the user scanf("%d",&num); //the integer entered by the user and it is stored in variable num (num%2==0)? printf("%d is even",num):printf("%d is odd",num); getch(); return 0; }
When the above code is executed ,it produces the following result
case 1
Enter a integer to check odd or even 5678 5678 is even
case 2
Enter a integer to check odd or even 6767 6767 is odd
Program 4
#include <stdio.h> #include <stdlib.h> int main() { int num;//variable declaration printf("Enter a integer to check odd or even\n"); //the program Asks input from the user scanf("%d",&num); //the integer entered by the user and it is stored in variable num if((num & 1)==0){ printf("%d is even number",num); } else{printf("%d is odd number",num);} getch(); return 0; }
When the above code is executed ,it produces the following result
case 1
Enter a integer to check odd or even 4 4 is even number
case 2
Enter a integer to check odd or even 5 5 is odd number
Program 5
#include <stdio.h> #include <stdlib.h> int main() { int num;//variable declaration printf("Enter a number to check even or odd\n"); //the program Asks input from the user scanf("%d",&num); //the integer entered by the user and it is stored in variable num if((num>>1)<<1==num) printf("%d is Even number",num); else printf("%d is Odd number",num); getch(); return 0; }
When the above code is executed ,it produces the following result
Case 1
Enter a number to check even or odd 4321 4321 is Odd number
Case 2
Enter a number to check even or odd 4326 4326 is Even number
Suggested for you
Data type in C language
Variable in C language
Similar post
Java Program to check whether the number is odd or even using operators
C Program to check whether the number is odd or even using operators
C++ Program to check whether the number is odd or even using operators
Python Program to check whether the number is odd or even using operators
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.