c语言 7-4

编写函数,返回将无符号整数的第pos位设置为1后的值。

1、

#include <stdio.h>

unsigned set(unsigned x, int pos)
{
    return (x | 1 << pos);
}

int main(void)
{
    unsigned x;
    int n;
    puts("please input two nonnegative integers.");
    printf("x = "); scanf("%u", &x);
    printf("n = "); scanf("%d", &n);
    
    printf("result: %u\n", set(x, n));
    return 0;
}

 

posted @ 2021-05-19 13:02  小鲨鱼2018  阅读(56)  评论(0编辑  收藏  举报