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

Comments: 0

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?