Q:

C Program to check a given number is even or odd using the function

0

C Program to check a given number is even or odd using the function

All Answers

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

#include <stdio.h>
 
int checkOddEven(int n1)
{   
    return (n1 & 1);//The & operator does a bitwise and,
}

int main()
{
    int n1;
	printf("\n\n Function : check the number is even or odd:\n");
	printf("------------------------------------------------\n");	     
    printf("Input any number : ");
    scanf("%d", &n1);

    // If checkOddEven() function returns 1 then the number is odd 
    if(checkOddEven(n1))
    {
        printf("The entered number is odd.\n\n");
    }
    else
    {
        printf("The entered number is even.\n\n");
    }
    return 0;
}

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now