- 0
Notifications Mark All Read
- Login
- Get Prime
Program for Even and Odd Numbers
Even and Odd Numbers
We will write a C program to display the given numbers is even or odd and the number will be entered by the user. This will help to understand the basic structure of programming. In this program , we will display the given numbers is even or odd easily by using proper syntax and algorithms.
Working of Program :
In the program, we will require some numbers from the user to display that given numbers is even or odd.
Important Note :
- If the number is completely divided by 2, then the number will be an even number.
- If the number is not completely divisible by 2, then the number will be an odd number.
Problem 1
Write a program to check whether the number is even or odd.
- Firstly, we have to enter the any number.
- Then print the number.
Code
#include<stdio.h> int main () { int num; printf ("Enter the number = "); scanf ("%d", &num); if (num % 2 == 0) printf ("%d is an even number.", num); else printf ("%d is an odd number.", num); return 0; }
Output
Enter the number = 45 45 is an odd number.
Note:
In the following program we will check whether a number is even or odd using third variable.
Problem 2
Write a program to check whether a number is even or odd.
- Firstly, we have to enter the any number.
- Then print the number.
Code
#include<stdio.h> int main() { int n; printf("Enter the number: "); scanf("%d", &n); if (n % 2 == 0) { printf("The given number is EVEN."); } else { printf("The given number is ODD."); } return 0; }
Output
Enter the number: 78 The given number is EVEN.
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment