Learn about Even or odd program without using modulus operator in C in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
Even or odd program without using modulus operator in C
Solution: By multiplying and dividing by two. Divide the number by two and multiply it by two; if the result is the same as the input, the number is an even number; otherwise, it is an odd number.
Source code:
#include<stdio.h>
int main()
{
int n;
printf("Enter a number:");
scanf("%d",&n);
if((n/2)*2==n)printf("Even");
else printf("Odd");
return 0;
}
Output:
Enter a number:4
Even
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Codes :
Even Odd Program in C using function
Even Odd Program in C Using for loop