Q:

Write C program to check even or odd using functions

0

Write C program to check even or odd using functions

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.

#include <stdio.h>
 
int isEven(int num)
{
    return !(num & 1);
}
int main()
{
    int num;
 
    // Inputting number from user
    printf("Enter any number: ");
    scanf("%d", &num);
 
    // If isEven() function return 0 then the number is even
    if(isEven(num))
    {
        //printing even number
        printf("The number is even.");
    }
    else
    {
        //printing odd number
        printf("The number is odd.");
    }
 
    return 0;
}

Result:

Enter any number: 123

The number is odd.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write C program to check prime and armstrong numbe... >>