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
", set(x, n));
    return 0;
}

原文地址:https://www.cnblogs.com/liujiaxin2018/p/14784636.html