C Program to Check Whether a Number is Even or Odd

C program to check a number is even or odd; Through this tutorial, we will learn how to find a number is even or odd in the c program with the help of function, modules operator, and ternary operator.

C Program to Check Whether a Number is Even or Odd

  • Algorithm to Check Whether a Number is Even or Odd
  • C Program to Check Even or Odd
  • C Program to Check Whether a Number is Even or Odd using Function
  • C Program to Check Whether a Number is Even or Odd using Ternary Operator

Algorithm to Check Whether a Number is Even or Odd

Use the following algorithm to write a program to check whether a number is even or odd; as follows:

  • Step 1: Start Program
  • Step 2: Read the number from user and store it in a.
  • Step 3: Find the number is even or odd using a % 2 == 0.
  • Step 4: Print number is even or odd
  • Step 5: Stop Program

C Program to Check Even or Odd

#include <stdio.h>
int main() {
    int num;
    printf("Enter an integer: ");
    scanf("%d", &num);

    // true if num is perfectly divisible by 2
    if(num % 2 == 0)
        printf("%d is even.", num);
    else
        printf("%d is odd.", num);

    return 0;
}

The output of the above c program; as follows:

Enter an integer: 10
10 is even.

C Program to Check Whether a Number is Even or Odd using Function

#include <stdio.h>
#include <stdlib.h>
int find_Num(int);//function prototype
int main()
{
    int num;
    printf("Enter a number to check odd or even :- ");
    scanf("%d",&num);
    find_Num(num);//calling the function
    return 0;
}
//create function
int find_Num(int num){//function definition
if(num%2==0){
    printf("\n%d is an even number",num);
}
else{
    printf("\n%d is an odd number",num);
}
}

The output of the above c program; as follows:

Enter a number to check odd or even :- 11
11 is an odd number

C Program to Check Whether a Number is Even or Odd using Ternary Operator

#include <stdio.h>
int main() {
    int num;
    printf("Enter an integer: ");
    scanf("%d", &num);

    (num % 2 == 0) ? printf("%d is even.", num) : printf("%d is odd.", num);
    return 0;
}

The output of the above c program; as follows:

Enter an integer: 15
15 is odd.

Recommended C Programs

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *