Even or Odd number in C using function

even-or-odd-number-in-c-using-function

Even or Odd number in C using function Program Description:

Write a Program to check whether the given number is an Even or Odd number in C using function. The program should accept a number from the user and detect if it is an even number or an odd number.

We can create a function called isEven (or isOdd), Which detects if the given number is an even number or an odd number.

Excepted Input and Output:

Input:

Enter a Number : 30

Output:

30 is a Even Number

Pre-Requisites:

Even or Odd number in C using function Algorithm:

  1. Take the input from the user and store it in a variable called number
  2. Create a function called isEven, Which takes the number as the input and check if the numberis Even number.
    • The isEven function returns boolean
    • If the number is an Even number, The isEven function returns true, Otherwise it will return False.
  3. Call the isEven function from the main function and pass the number as the input.
  4. Check the return value of isEven and print the result accordingly.
    • If the return value is true, Then number is an Even Number.
    • If the return value is false, Then number is an Odd Number.
  5. Stop the program.

Program to check Even or Odd Number in C using Function

Prototype details of the isEven function.

  • <strong>bool</strong> <strong>isEven</strong>(int number)
  • function_name : isEven
  • arguments_list: int
  • return_type : bool

Program Output:

Compile the program.

$ gcc even-odd.c

Run the executable file.

even-or-odd-number-program-in-c-using-function

As we can see from the above output, We are getting the desired results.

Related Programs:

Venkatesh

Hi Guys, I am Venkatesh. I am a programmer and an Open Source enthusiast. I write about programming and technology on this blog.

You may also like...

2 Responses

  1. […] Program to Check Even or Odd number using Function […]

  2. […] two variables to track the count of the total number of even numbers and odd numbers. So Initialize the nEven and nOdd variables with […]

Leave a Reply