c program to check no. is even or odd without using conditional operator !!

Gaurav Deshmukh
@gaurav-ToXXkA โ€ข Oct 26, 2024
#include<stdio.h>
#include<conio.h>

int main()
{
  int no;
  char ch[0]="Even";
  char ch[1]="odd";
  printf("Enter a no. \t");
  scanf("%d",&no);

  printf("\n The no. is %s",ch[no%2]);

return (0);
}

// in above c code using % operator and array we can find the no. is even or odd also we can perform it by using bitwise AND operato (&) and AND operator (&&).................
I gave u the hint can anybody is able to write 2nd program ...๐Ÿ˜‰๐Ÿ˜€//

o/p--> Enter a no. 7
The no. is odd

Enter a no. 4
The no. is Even

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Anoop Kumar

    @anoop-kumar-GDGRCn • Sep 19, 2013

    Good program but in wrong category.
    You should post computer and IT related stuffs at following section:
    #-Link-Snipped-#

  • nareshkumar6539

    @nareshkumar6539-BKuVbx • Sep 19, 2013

    Gaurav v. Deshmukh
    #include<stdio.h>
    #include<conio.h>
    
    int main()
    {
      int no;
      char ch[0]="Even";
      char ch[1]="odd";
      printf("Enter a no. \t");
      scanf("%d",&no);
    
      printf("\n The no. is %s",ch[no%2]);
    
    return (0);
    }
    
    // in above c code using % operator and array we can find the no. is even or odd also we can perform it by using bitwise AND operato (&) and AND operator (&&).................
    I gave u the hint can anybody is able to write 2nd program ...๐Ÿ˜‰๐Ÿ˜€//

    o/p--> Enter a no. 7
    The no. is odd

    Enter a no. 4
    The no. is Even

    When we use logical and or bit wise first it will convert number into binary format then it will perform the operation.
    When we perform Logical and or Bitwise and operation with NUMBER&&1 it will give
    one means it is ODD number it will give 0 means EVEN number.
    (NUMBER&&1)?"ODD":"EVEN" or (NUMBER&1)?"ODD":"EVEN"

  • rahul69

    @rahul69-97fAOs • Sep 20, 2013

    nareshkumar6539When we use logical and or bit wise first it will convert number into binary format then it will perform the operation.
    When we perform Logical and or Bitwise and operation with NUMBER&&1 it will give
    one means it is ODD number it will give 0 means EVEN number.
    (NUMBER&&1)?"ODD":"EVEN" or (NUMBER&1)?"ODD":"EVEN"

    Logical And will not work! because logical And can only check if the number is non zero, to check even odd, you will have to use bitwise And ie '&'

  • Vinut47

    @vinut47-6dkCRt • Jun 24, 2016

    7 easy ways to find whether a number id odd/even.
    #-Link-Snipped-#