C Program to check if a number is even or odd in a given interval
C Program to check if a number is even or odd in a given interval
#include <stdio.h>
// function declaration
int isEven(int);
void main()
{
int start, end, num;
printf("Enter the number to start: ");
scanf("%d", &start);
printf("Enter the number to end: ");
scanf("%d", &end);
printf("\nEven numbers-\n");
for (num = start; num <= end; num++)
{
if (isEven(num))
printf("%d\n", num);
}
printf("\nOdd numbers-\n");
for (num = start; num <= end; num++)
{
if (!isEven(num))
printf("%d\n", num);
}
}
// function definition
int isEven(int num)
{
return !(num & 1);
}
Output
Enter the number to start: 1 Enter the number to end: 10 Even numbers- 2 4 6 8 10 Odd numbers- 1 3 5 7 9