What do you mean by an EVIL number?
An Evil number is a number that has an even number of 1's in its binary expansion.
An Evil number is an non-negative number.
For example 9 is an Evil number.
because binary expansion of number 9 is = 1001
and binary expansion 1001 has 2 number of 1's
since 2 is an even number ; We can say the number 9 is an EVIL number.
Similarly number 3,6,15 are examples of EVIL number.
C Program
#include<stdio.h>void IsEvil(int number);
int main()
{
int n,num,B=0,rem,base=1;
printf("Enter an Integer number : ");
scanf("%d",&n);
num = n;
while (n > 0)
{
rem = n % 2;
B = B + rem * base;
base = base * 10;
n = n / 2;
}
printf("Binary representation of %d is : %d",num,B);
IsEvil(B);
return 0;
}
void IsEvil(int number)
{
int count=0,r;
while(number > 0)
{
r = number % 2;
if (r == 1)
{
count = count + 1;
}
number = number / 10;
}
printf("\nNumber of 1's = %d",count);
if (count % 2 == 0)
{
printf("\nThe number you entered is an EVIL number.");
}
else
{
printf("\nThe number you entered is NOT an EVIL number.");
}
}
INPUT && OUTPUT
0 Comments