Utopper SkillUtopper Skill
  • Programming
    • Programming Examples
  • Interview Questions
    • DevOps Interview Questions
    • Android Interview Questions
  • How to
  • Tools
  • Top 10
  • Book Summaries
Reading: C program to Find Even or Odd Number
Share
Utopper SkillUtopper Skill
Search
  • Book Summaries
  • Programming Examples
  • C Programming Example
  • Interview Question
  • How to
  • Top 10
Follow US
Utopper Skill > Programming Examples > C Programming Example > C program to Find Even or Odd Number
C Programming ExampleProgramming Examples

C program to Find Even or Odd Number

Utopper Skill Team
By Utopper Skill Team Last updated: March 1, 2023
Share
6 Min Read
Even or odd program in c language
SHARE
Table of Content
What is the odd number?What is the even number?Approach to find Even and Odd Numbers in c LanguagePseudo code to check even or odd in C LanguageC program to check even or odd numbers.C Program to Check Odd or Even Using the Ternary Operator

Finding out whether a given integer is even or odd is a common need in computer programming. Numerous applications, including sorting numbers, confirming user input, and carrying out mathematical calculations, can benefit from this. It is simple to detect whether a number is even or odd in the C programming language by using the modulus operator%. With the help of a straightforward conditional statement, we will show you how to use C to determine whether a given integer is even or odd.

Even or odd program in c language

What is the odd number?

An odd number is a whole number that is not divisible by 2 without leaving a remainder. In other words, an odd number is any integer that can be expressed in form 2n + 1, where n is an integer. Examples of odd numbers include 1, 3, 5, 7, 9, -1, -3, -5, -7, and so on. The set of odd numbers can be represented as { …, -5, -3, -1, 1, 3, 5, … }.

What is the even number?

An even number is a whole number that is divisible by 2 without leaving a remainder. In other words, an even number is any integer that can be expressed in form 2n, where n is an integer. Examples of even numbers include 2, 4, 6, 8, 10, -2, -4, -6, -8, and so on. The set of even numbers can be represented as { …, -4, -2, 0, 2, 4, 6, … }.

Approach to find Even and Odd Numbers in c Language

To find whether a given number is even or odd in C language, you can follow this approach:

  1. Prompt the user to enter a number.
  2. Read the input number using scanf().
  3. Use the modulus operator % to check if the remainder of the division of the number by 2 is zero or not.
  4. If the remainder is zero, then the number is even, and you can print a message indicating that.
  5. If the remainder is not zero, then the number is odd, and you can print a different message.

Pseudo code to check even or odd in C Language

Sure, here’s the pseudocode to check whether a given number is even or odd in a C program:

1. Prompt the user to enter a number
2. Read the input number
3. Check if the number is even or odd using the modulus operator %
4. If the result of the modulus operator is 0, the number is even
5. If the result of the modulus operator is not 0, the number is odd
6. Print the appropriate message based on whether the number is even or odd

C program to check even or odd numbers.

#include <stdio.h>

int main() {
    int number;
    
    // Step 1: Prompt the user to enter a number
    printf("Enter a number: ");
    
    // Step 2: Read the input number
    scanf("%d", &number);
    
    // Step 3: Check if the number is even or odd
    if (number % 2 == 0) {
        // Step 4: If the result of the modulus operator is 0, the number is even
        printf("%d is even", number);
    } else {
        // Step 5: If the result of the modulus operator is not 0, the number is odd
        printf("%d is odd", number);
    }
    
    return 0;
}

Output :

Enter a number: 10
10 is even.
Enter a number: 7
7 is odd.
Enter a number: -12
-12 is even.

C Program to Check Odd or Even Using the Ternary Operator

#include <stdio.h>

int main() {
    int number;

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

    number % 2 == 0 ? printf("%d is even.\n", number) : printf("%d is odd.\n", number);

    return 0;
}

The ternary operator?: checks whether the remainder of the number’s division by 2 is zero in this programme. We print “even” if the remainder is zero. Otherwise, we print an odd number message.

The ternary operator simplifies if-else statements. Ternary operators have this syntax:

condition ? value_if_true : value_if_false;

In the above program, the condition is number % 2 == 0, which checks whether the remainder of the division of the number by 2 is zero or not. If the condition is true, the value of true is printf("%d is even.\n", number), which prints a message indicating that the number is even. Otherwise, the value if false is printf("%d is odd.\n", number), we print a message indicating the number is odd.

You can also check the Other C Programs :

  • Palindrome Number
  • Fibonacci Series in C
  • Prime Number in C
TAGGED:C Program Examples
Share This Article
Facebook Twitter Whatsapp Whatsapp Telegram Copy Link Print
Previous Article How to Become an Android Developer How to Become an Android Developer: Step-by-Step Guide to Building Your Skills
Next Article C Program To Print ASCII Value of a Character C Program To Print ASCII Value of a Character
Most Popular
Learn C Programming (Basic to Advanced)
Pointer Arithmetic in C
Utopper Skill Author By Utopper Skill Author
Learn C Programming (Basic to Advanced)
Sizeof Operators in C
Utopper Skill Author By Utopper Skill Author
Book Summary of The 7 Habits of Highly Effective People
Book Summary of The 7 Habits of Highly Effective People By Stephen R. Covey
Utopper Skill Author By Utopper Skill Author
Learn C Programming (Basic to Advanced)
Return Array from a Function in C
Utopper Skill Author By Utopper Skill Author
Learn C Programming (Basic to Advanced)
Function Pointer in C
Utopper Skill Author By Utopper Skill Author

You Might Also Like

C++ Program To Print Prime Numbers From 1 To N
C Programming ExampleProgramming Examples

C++ Program To Print Prime Numbers From 1 To N

11 Min Read
C Program to Print Your Own Name
Programming ExamplesC Programming Example

C Program to Print Your Own Name with Example

2 Min Read
C Program To Convert Fahrenheit To Celsius
C Programming ExampleProgramming Examples

C Program To Convert Fahrenheit To Celsius

5 Min Read
C Program To Find LCM of Two Numbers
Programming ExamplesC Programming Example

C Program To Find LCM of Two Numbers

6 Min Read

Mail : [email protected]

Privacy Policy | DISCLAIMER | Contact Us

Learn

  • learn HTML
  • learn CSS
  • learn JavaScript

Examples

  • C Examples
  • C++ Examples
  • Java Examples

Study Material

  • Interview Questions
  • How to
  • Hosting
  • SEO
  • Blogging

 

© 2024 : UTOPPER.COM | Owned By : GROWTH EDUCATION SOLUTIONS PRIVATE LIMITED
Welcome Back!

Sign in to your account

Lost your password?