编写reset_n函数,返回将无符号整数x的第pos为开始的n位设为0后的值。
1、
#include <stdio.h>
unsigned reset_n(unsigned x, int pos, int n)
{
int i;
for(i = pos; i <= pos + n - 1; i++)
{
x = (x & (~(1 << i)));
}
return x;
}
int main(void)
{
unsigned x;
int pos, i;
puts("please input three nonnegative integers.");
printf("x = "); scanf("%u", &x);
printf("pos = "); scanf("%d", &pos);
printf("i = "); scanf("%d", &i);
printf("result: %u
", reset_n(x, pos, i));
return 0;
}