zoukankan      html  css  js  c++  java
  • c语言 7-2

    1、

    #include <stdio.h>
    #include <math.h>
    
    int main(void)
    {
        unsigned x;
        int n;
        puts("please input an unsigned number and an integer.");
        printf("x = "); scanf("%u", &x);
        printf("n = "); scanf("%d", &n);
        
        (x << n) == x * (int)pow(2, n) ? printf("equally.
    ") : printf("unequally.
    ");
        (x >> n) == x / (int)pow(2, n) ? printf("equally.
    ") : printf("unequally.
    ");
        
        return 0;
    }

    2、

    #include <stdio.h>
    #include <stdio.h>
    
    int main(void)
    {
        unsigned x;
        int n;
        puts("please input an unsigned number and an integer.");
        printf("x = "); scanf("%u", &x);
        printf("n = "); scanf("%d", &n);
        
        int left = x << n;
        int leftve = x;
        int i;
        for(i = 1; i <= n; i++)
        {
            leftve *= 2;
        }
        if(left == leftve)
            puts("left equally.");
        else
            puts("left unequally.");
            
        int right = x >> n;
        int rightve = x;
        for(i = 1; i <= n; i++)
        {
            rightve /= 2;
        }
        if(right == rightve)
            puts("right equally");
        else
            puts("right unequally");
                
        return 0;
    }

    3、

    #include <stdio.h>
    #include <limits.h>
    
    int main(void)
    {
        unsigned x;
        puts("please input an unsigned integer.");
        do
        {
            printf("x = "); scanf("%u", &x);
            if(x > UINT_MAX)
                puts("It's too big!");
        }
        while(x > UINT_MAX);
        
        printf("verify left move 3 unit:  %u = %u
    ", x << 3, x * 2 * 2 * 2);
        printf("verigy right move 3 unit:  %u = %u
    ", x >> 3, x / 2 / 2 / 2);
        
        return 0;
    }

    4、

    #include <stdio.h>
    
    int main(void)
    {
        unsigned x;
        int n;
        puts("please input an unsigned integer and integer.");
        printf("x = "); scanf("%u", &x);
        printf("n = "); scanf("%d", &n);
        
        int left = x, left_verify = x;
        left <<= n;
        printf("left = %u
    ", left);
        int i;
        for(i = 1; i <= n; i++)
        {
            left_verify *= 2;
        }
        printf("left_vefigy = %u
    ", left_verify);
        
        return 0;
    }

    #include <stdio.h>
    
    int main(void)
    {
        unsigned x;
        int n;
        puts("please input an unsigned integer and an integer.");
        printf("x = "); scanf("%u", &x);
        printf("n = "); scanf("%d", &n);
        
        int right = x, right_verify = x;
        right >>= n;
        printf("right    = %u
    ", right);
        int i;
        for(i = 1; i <= n; i++)
        {
            right_verify /= 2;    
        } 
        printf("right_verify = %u
    ", right_verify);
        
        return 0;
    } 

  • 相关阅读:
    update语句
    java List和数组相互转换方法
    mysql查最大字符串
    Mybatis各种模糊查询
    mysql 递归查询父节点 和子节点
    String类型根据逗号分隔转为list
    This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its de 错误解决办法
    java中String数组和List的互相转化
    实现List集合中数据逆序排列
    String字符串去掉双引号
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14782423.html
Copyright © 2011-2022 走看看