首页 > 编程语言 > 详细

c语言 7-4

时间:2021-05-19 16:50:52      阅读:22      评论:0      收藏:0      [点我收藏+]

编写函数,返回将无符号整数的第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;
}

技术分享图片

 

c语言 7-4

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

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