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

    1、

    #include <stdio.h>
    
    unsigned rrotate(unsigned x, int n)
    {
        return x >> n;
    }
    
    unsigned lrotate(unsigned x, int n)
    {
        return x << n;
    }
    
    int main(void)
    {
        unsigned x; int n;
        puts("please input the test number and move bits.");
        printf("x = "); scanf("%u", &x);
        printf("n = "); scanf("%u", &n);
        
        printf("right : %u  | left : %u
    ", rrotate(x, n), lrotate(x, n));
        
        return 0;
    }

    2、

    #include <stdio.h>
    
    unsigned rrotate(unsigned x, int n)
    {
        return x >> n;
    }
    
    unsigned lrotate(unsigned x, int n)
    {
        return x << n;
    }
    
    int main(void)
    {
        unsigned x; int n;
        puts("please input the test number and move bits.");
        printf("x = "); scanf("%u", &x);
        printf("n = "); scanf("%d", &n);
        
        int i;
        for(;;)
        {
            puts("choose:  1 →right;2 →left");
            printf("i = "); scanf("%d", &i);
            if(i == 1 | i == 2)
                break;
            puts("input error, 1 or 2 ?"); 
        }
        
        if(i == 1)
            printf("right: %u
    ", rrotate(x, n));
        else
            printf("left : %u
    ", lrotate(x, n));
            
        return 0;
    }

    3、

    #include <stdio.h>
    
    unsigned rrotate(unsigned x, int n)
    {
        return x >> n;
    }
    
    unsigned lrotate(unsigned x, int n)
    {
        return x << n;
    }
    
    int main(void)
    {
        unsigned x; int n;
        puts("please input the test number and move bits.");
        printf("x = "); scanf("%u", &x);
        printf("n = "); scanf("%d", &n);
        
        int i;
        while(!0)
        {
            puts("choose: 1 →right; 2 →left");
            printf("i = "); scanf("%d", &i);
            
            if(i == 1 || i == 2)
                break;
            puts("input error! 1 or 2 ?");
        } 
        
        if(i == 1)
            printf("right: %u
    ", rrotate(x, n));
        else
            printf("left : %u
    ", lrotate(x, n));
        
        return 0;
    }

    4、

    #include <stdio.h>
    
    unsigned rrotate(unsigned x, int n)
    {
        return x >> n;
    }
    
    unsigned lrotate(unsigned x, int n)
    {
        return x << n;
    }
    
    int main(void)
    {
        unsigned x; int n;
        puts("please input the test number and move bits.");
        printf("x = "); scanf("%u", &x);
        printf("n = "); scanf("%d", &n);
        
        int i;
        do
        {
            puts("choose i: 1 →right; 2 →left");
            printf("i = "); scanf("%d", &i);
            if(i < 1 || i > 2)
                puts("input error! 1 or 2 ?");
        }
        while(i < 1 || i > 2);
        
        if(i == 1)
            printf("right: %u
    ", rrotate(x, n));
        else
            printf("left : %u
    ", lrotate(x, n));
            
        return 0;
    }

  • 相关阅读:
    床前思
    捍卫永恒的爱情,注定是一场梦境(转)
    耳朵生豆
    有志人士自行创业之十大策略
    思念熟睡的你
    如何用好云的弹性
    测试一年多,上线就崩溃!微服务到底应该怎么测试?
    解决Tengine健康检查引起的TIME_WAIT堆积问题
    解读容器的 2020:寻找云原生的下一站
    Java 过滤器的作用
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14792973.html
Copyright © 2011-2022 走看看