Introduction
Check a number odd or even without using bit and modulus operator program shows how to check a number odd or even without using a % operator. Here in the for loop % operator is not used, required number is compared with all even numbers, if it is a even number shows output as even number and if it is odd number shows output as odd number.
#include<stdio.h> #include<conio.h> void main() { int n; clrscr(); printf("\n Enter a number:"); scanf("%d",&n); for(int i=2;i<=n;i+=2) { if(i==n) break; } if(i==n) printf("%d is even",i); else printf("%d is odd",i); getch(); }
Comments/Suggestions are invited. Happy coding......!
Comments Post a Comment