• 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;
    }

  • 相关阅读:
    React 生命周期
    React 总结
    系统后台设置
    数据库的事务日志已满,起因为"LOG_BACKUP"。
    webpack 打包器
    地图API
    ES6 与 React
    前端流行的技术
    Javascript 函数声明、函数表达式与匿名函数自执行表达式
    Javascript 解读与思想
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14792717.html
Copyright © 2020-2023  润新知