首页 > 编程语言 > 详细

c语言 7-2

时间:2021-05-21 12:05:13      阅读:17      评论:0      收藏:0      [点我收藏+]

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\n", x << n, x * (unsigned)pow(2, n));
    printf("move  right : %u | devide   power of 2 : %u\n", 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\n") : printf("unequally\n");
    
    (x >> n) == x / (unsigned)pow(2, n) ? printf("equally\n") : printf("uneauqlly\n");

    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\n") : printf("unequally\n");
    
    unsigned right, vright = x;
    right = x >> n;
    
    for(i = 1; i <= n; i++)
    {
        vright /= 2;    
    } 
    
    right == vright ? printf("equqlly\n") : printf("unequally\n");
    
    return 0;
}

技术分享图片

 

c语言 7-2

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!