C Program to Check Even Or Odd Number

This program will compute whether or not there is an odd or even number of ones. User can only input integer numbers. Set up for loop for bit comparison.
C program to check odd or even, check whether a number entered by user is odd or even, C program for odd or even number,odd or even in c program c# iseven how to determine if a number is odd or even C check for odd number how to check if a number is odd in C how to find odd numbers objective c odd number c get odd numbers
Check whether the given Number is Even or Odd

Solution:
//how to determine if a number is odd or even.
//C Program to check whether the given Number is Even or Odd.
//Write a C Program to check if number is odd or even number.
//C Program to print whether or not there is an odd or even number.
#include <stdio.h>

int initial;
int counter = 0;
int mod;
int result;
int comparator = 1;
   
int main () {  
/* Read in value of which to compute factorial */
printf("This program will compute whether or not there is an odd or even number of ones.\nPlease enter a number: ");
scanf("%d", &initial);
printf("\n");

/*Check for invalid input*/
while (initial < 0) {
        printf("This input is not valid. Only positive integers up to 2^31 are accepted\nEnter N: ");
scanf("%d", &initial);
      printf("\n");
}

/* set up for loop for bit comparison */
for(; initial > 0; initial = initial >> 1)  {
counter += (initial&1);
}    
     
/* Check if odd number or even number of 1s and print answer*/
if ((counter%2) == 1) {
printf("Your value is odd\n");
}
else {
printf("Your value is even\n");
}
    return 0;
}

This C Program to Check whether the given Number is Even or Odd Ones.


Learn More :