TechSapphire Sunday, 2018-12-16, 6:30 PM
Site menu
Login form
News
Play Games
  • Deep Freeze
  • Ice Slide
  • Gyroball
  • Fat Fish
  • Bush Royal Rampage
  • How to print 0 if input is even and 1 if input is odd without using control statements?

    Solution:

    #include<stdio.h>

    #include<conio.h>

    Int main()

    {

    Int num;

    Printf("Enter any number:ā€);

    Scanf("%dā€,&num);

    Printf("result = %dā€,1&num);

    getch();              

    }

    Explanation:

    How this code work?

    For this you should know about & operator. This is binary AND operator. And there is an common fact about even number i.e. every even number has 0 at the end in binary form and every odd number has 1 at the end in binary form.

    Categories
    Programming [27]
    Tips for programming
    Security [2]
    Security Tips
    Google [1]
    Use google faster then ever you use
    Project [14]
    HTML [2]
    Electronics [0]
    Data Structure [0]
    Database [16]
    SQL SERVER
    SSRS [1]
    Sql Server Reporting Services
    Copyright MyCorp © 2018