C Program to check if a number is even or odd using function
C Program to check if a number is even or odd using function
#include <stdio.h>
// function declaration
int isEven(int);
void main()
{
int num;
printf("Enter the number: ");
scanf("%d", &num);
if(isEven(num))
printf("%d is an even number", num);
else
printf("%d is an odd number", num);
}
// function definition
int isEven(int num)
{
if (num % 2 == 0)
return 1;
return 0;
}
C Program to check if a number is even or odd using function and bitwise operator
#include <stdio.h>
// function declaration
int isEven(int);
void main()
{
int num;
printf("Enter the number: ");
scanf("%d", &num);
if(isEven(num))
printf("%d is an even number", num);
else
printf("%d is an odd number", num);
}
// function definition
int isEven(int num)
{
return !(num & 1);
}
Output
Enter the number: 9 9 is an odd number