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

    1、

    #include <stdio.h>
    
    unsigned rrotate(unsigned x, int n)
    {
        printf("rrotate = %u
    ", x >> n);
    }
    
    unsigned lrotate(unsigned x, int n)
    {
        printf("lrotate = %u
    ", x << n);
    }
    
    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);
        
        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, n, a;
        puts("please input two unsigned integers.");
        printf("x = "); scanf("%u", &x);
        printf("n = "); scanf("%u", &n);
        
        for(;;)
        {
            puts("a = 1: move right;  a = 2: move left.");
            printf("a = "); scanf("%u", &a);
            if(a == 1 || a == 2)
            {
                break;
            }
            puts("input error. try again.");
        }
        if(a == 1)
        {
            printf("right move result: %u
    ", rrotate(x, n));
        }
        else
        {
            printf("left move result: %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, a;
        puts("please input an unsigned integer and an integer.");
        printf("x = "); scanf("%u", &x);
        printf("n = "); scanf("%d", &n);
        
        while(!0)
        {
            puts("a = 1: move right;   a = 2: move left.");
            printf("a = "); scanf("%d", &a);
            
            if(a == 1 || a == 2)
            {
                break;
            }
            puts("input error, try again.");
        }
        if(a == 1)
        {
            printf("right move result: %u
    ", rrotate(x, n));
        }
        else
        {
            printf("left move result: %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, a;
        puts("please input two nonnegative integers.");
        printf("x = "); scanf("%u", &x);
        printf("n = "); scanf("%d", &n);
        
        do
        {
            puts("a = 1: move right.  a = 2: move left.");
            printf("a = "); scanf("%d", &a);
            if(a != 1 && a != 2)
                puts("input error; try again.");
        }
        while(a != 1 && a != 2);
        
        if(a == 1)
        {
            printf("right move result: %u
    ", rrotate(x, n));
        }
        else
        {
            printf("left move result: %u
    ", lrotate(x, n));
        }
        return 0;
    }

    5、

    #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 value of unsigned x and int n.");
        printf("x = "); scanf("%u", &x);
        printf("n = "); scanf("%d", &n);
        
        printf("%u move to right %d bits is :%u
    ", x, n, rrotate(x, n));
        printf("%u move ro left %d  bits is :%u
    ", x, n, lrotate(x, n));
        
        return 0;
    }

  • 相关阅读:
    Vocabulary Recitation 2020/05/06
    java set TreeSet详解
    vue快速入门~必备基础知识(一)下~过滤器
    vue快速入门~必备基础知识(一)上
    vue入门(二)基于前面的基础的一个小Demo
    Annotation注释详解~
    泛型~详解~
    Collections工具类详解
    TreeMap实现类和SortMap接口
    Map集合-主要HashMap和Hashtable
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14782829.html
Copyright © 2011-2022 走看看