C Program to Check Whether the Number is Even or Odd.

In this C program, we will determine whether a given number is even or odd. An even number is an integer that is exactly divisible by 2 without leaving a remainder, while an odd number is an integer that leaves a remainder of 1 when divided by 2. 

For Example:
2, 4, 6, 8, 10, etc are Even numbers.
1, 3, 7, 11, 13, etc are Odd numbers.

Steps to Check Whether a Number is Even or Odd:

Step 1: Take an Input number from the user.
Step 2: Use the modulo operator (%) to check if the number leaves a remainder of 0 when divided by 2.
Step 3: If the remainder is 0, the number is even. Otherwise, it is odd.
Step 4: Display the result indicating whether the number is even or odd.

C Program to check Even or Odd.

//C program to check even or odd number
#include <stdio.h>

int main() {
    int number;

    printf("Enter an integer: ");
    scanf("%d", &number);

    // Check if number is even or odd using the modulo operator
    if (number % 2 == 0) {
        // remainder is 0, the number is even
        printf("%d is an even number.\n", number);
    } else {
        // remainder is 1, the number is odd
        printf("%d is an odd number.\n", number);
    }

    return 0;
}
Output:
Enter an integer: 10
10 is an even number.

In the above example code, the user enters an integer number, and then our program checks if the number is divisible by two or not. If the number is perfectly divisible by 2 then we say that the given number is Even else we say the given number is Odd.

⚡ Please share your valuable feedback and suggestion in the comment section below or you can send us an email on our offical email id ✉ algolesson@gmail.com. You can also support our work by buying a cup of coffee ☕ for us.

Similar Posts

No comments:

Post a Comment


CLOSE ADS
CLOSE ADS