top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

In C programming, what command or code can be used to determine if a number of odd or even?

+1 vote
In C programming, what command or code can be used to determine if a number of odd or even?
posted Dec 2, 2014 by Vinitha

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

4 Answers

+2 votes
Best answer

if LSB bit is set ,the given no is odd otherwise given no is even.

#include <stdio.h>
int num_odd_even(unsigned int num)
      if(num & 1)
          printf("Given no is odd\n");
      printf("given no is even");
answer Dec 2, 2014 by Bheemappa G
+1 vote

There is no command for finding the number is even or odd.
but through command line input you can make your program in a such way that from next time you can use its executable file as a command.

main(int argc,char **argv)
        int i,num;
         printf("No argument is given\n");

             num = atoi(argv[i]);
             if (num%2==0)
                printf("%d is even\n",num);
                printf("%d is odd\n",num);
answer Dec 2, 2014 by Chirag Gangdev
+1 vote

printf("%s", (number & 1) ? "ODD" : "EVEN");

answer Dec 4, 2014 by sivanraj
0 votes

There is no single command or function in C that can check if a number is odd or even. However, this can be accomplished by dividing that number by 2, then checking the remainder. If the remainder is 0, then that number is even, otherwise, it is odd. You can write it in code as:


int main(){

    int number;

    printf("Enter any integer: ");

    if(number % 2 ==0)
         printf("%d is even number.",number);
         printf("%d is odd number.",number);

    return 0;


Sample output:
Enter any integer: 5
5 is odd number.
answer Dec 2, 2014 by Shivaranjini
Similar Questions
+4 votes

Write the function READ, which is passed two double pointers pointing to the head pointers of two linked lists.

One list will hold even integers, the other one will hold odd integers. READ reads a series of integers. It separates adds odd integers to the first list, and even ones to the second, all in sorted order.

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.