c语言 7-2

1、

#include <stdio.h>
#include <math.h>

int main(void)
{
    unsigned x, n;
    printf("test number:  "); scanf("%u", &x);
    printf("move bits  :  "); scanf("%u", &n);
    
    printf("move   left : %u | multiply power of 2 : %u
", x << n, x * (unsigned)pow(2, n));
    printf("move  right : %u | devide   power of 2 : %u
", x >> n, x / (unsigned)pow(2, n));
    
    return 0; 
}

2、

#include <stdio.h>
#include <math.h>

int main(void)
{
    unsigned x, n;
    puts("please input the test number and move bits.");
    printf("test number  = "); scanf("%u", &x);
    printf("move bits    = "); scanf("%u", &n);
    
    (x << n) == x * (unsigned)pow(2, n) ? printf("equally
") : printf("unequally
");
    
    (x >> n) == x / (unsigned)pow(2, n) ? printf("equally
") : printf("uneauqlly
");

    return 0;
}

3、

#include <stdio.h>

int main(void)
{
    unsigned x, n;
    puts("please input the test number and move bits.");
    printf("x = "); scanf("%u",  &x);
    printf("n = "); scanf("%u",  &n);
    
    unsigned left, vleft = x;
    left = x << n;
    
    int i;
    for(i = 1; i <= n; i++)
    {
        vleft *= 2;
    }
    
    left == vleft ? printf("equally
") : printf("unequally
");
    
    unsigned right, vright = x;
    right = x >> n;
    
    for(i = 1; i <= n; i++)
    {
        vright /= 2;    
    } 
    
    right == vright ? printf("equqlly
") : printf("unequally
");
    
    return 0;
}

原文地址:https://www.cnblogs.com/liujiaxin2018/p/14792717.html