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.\n") : printf("unequally.\n");
(x >> n) == x / (int)pow(2, n) ? printf("equally.\n") : printf("unequally.\n");
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\n", x << 3, x * 2 * 2 * 2);
printf("verigy right move 3 unit: %u = %u\n", x >> 3, x / 2 / 2 / 2);
return 0;
}
原文:https://www.cnblogs.com/liujiaxin2018/p/14782423.html