Even Odd Program In C Language

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Here is an example of a C program that checks if a number is even or odd:

Copy code

#include <stdio.h> int main() {    int num;    printf("Enter an integer: ");    scanf("%d", &num);    if (num % 2 == 0) {        printf("%d is even.", num);    } else {        printf("%d is odd.", num);    }    return 0; }

The program prompts the user to enter an integer, which is stored in the variable "num". The modulus operator (%), which returns the remainder of a division operation, is used to check if the number is even or odd. If the remainder when "num" is divided by 2 is 0, the number is even. If the remainder is not 0, the number is odd. The program then prints out a message indicating whether the number is even or odd.

You can also use bitwise operator instead of modulus operator to check if a number is even or odd:

Copy code

if (num & 1 == 0) {    printf("%d is even.", num); } else {    printf("%d is odd.", num); }

Here the bitwise operator & will perform a bit-by-bit 'AND' operation. If the last bit of the number is 0 then the number is even otherwise it's odd.

5. Flow Control

0 Comments

Start the conversation!

Be the first to share your thoughts

Frequently Asked Questions About Sciaku Courses & Services

Quick answers to common questions about our courses, quizzes, and learning platform

Didn't find what you're looking for?

help_center Contact Support

Sciaku (सियाकु)

Sciaku (सियाकु) provides you a technical and programming content like Java Programming, Python Programming, C Programming,Android Development, Web Development, etc. Learn how to make software, website, and applications here and also we have industrial internship for you.

Contact

G20, Gopal Vihar Colony, Noida Sector 2, Uttar Pradesh, India, 201301

info@sciaku.com

Copyright © 2022-2025 Created by ❤️ Sciaku

Privacy Policy | Terms & Conditions | Refunds Policy