Saturday 11 November 2017

C Program to Check whether the given Integer has an Alternate Pattern


Code:

#include

void main()
{
    int num, x, y, count = 0;

    printf("enter the number:");
    scanf("%d", &num);
    x = num << 1;
    y = x ^ num;
    y = y + 1;

    /* Checks if the number is in powers of 2 */
    while ((y / 2) != 0)
    {
        if (y % 2 != 0)
        {
            count++;
            break;
        }
        else
        {
            y = y / 2;
        }
    }
    if (count)
    {
        printf("false");
    }
    else
    {
        printf("true");
    }
}


Output:

enter the number:85
true
$ a.out
enter the number:87
false


More C Programs:













100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...