【c语言】推断一个数是不是2的n次方
// 推断一个数是不是2的n次方 #include <stdio.h> void judge_n(int a)
{
int b = a - 1;
if ((a & b) == 0)
{
printf("是2的n次方\n");
return;
}
else
{
printf("不是2的n次方\n");
return;
}
} int main()
{
judge_n(2);
judge_n(3);
judge_n(4);
return 0;
}
【c语言】推断一个数是不是2的n次方的更多相关文章
- 【C语言】推断一个数的奇偶(位操作)
//推断一个数的奇偶 #include <stdio.h> int is_signal(int num) { if (num & 1) return 1; else return ...
- 【c语言】推断一个数是奇偶数
// 推断一个数是奇偶数 #include <stdio.h> void judge_sd(int a) { if ((a & 1) == 0) { printf("是偶 ...
- 【C语言】推断一个数是否为2的n次方
//推断一个数是否为2的n次方 #include <stdio.h> int is_two_n(int num) { if ((num&(num - 1))) //去掉一个1,推断 ...
- YTU 2422: C语言习题 n个数逆序
2422: C语言习题 n个数逆序 时间限制: 1 Sec 内存限制: 128 MB 提交: 150 解决: 96 题目描述 将n(n<20)个数按输入时顺序的逆序排列,用函数实现. 输入 ...
- C语言-实例3个数由小到大排序
VS2012 //C语言实例 3个数由小到大排序 #include <stdio.h> void main() { int a, b, c, t; printf("Please ...
- c语言高速推断一个数是偶数还是奇数
#include <stdio.h> int main() { int a; while(1) { printf("please input the number:\n" ...
- 【转载】C语言 构建参数个数不固定函数
深入浅出可变参数函数的使用技巧本文主要介绍可变参数的函数使用,然后分析它的原理,程序员自己如何对它们实现和封装,最后是可能会出现的问题和避免措施. VA函数(variable argument fun ...
- c语言推断数是否是素数
这是推断数是否是素数.网络版非常.我觉得有点问题.今天一个朋友问我这个问题.我知道,今天,我把自己的代码,非常实用哦!. #include<stdio.h> #include<mat ...
- c语言判断一个数是否为偶数
#include <stdio.h> #include <stdbool.h> _Bool isOu(int n){ //高度注意:&的优先级低于== )==){ re ...
随机推荐
- firefox 自写扩展改版,总结
自己写的扩展,油猴功能,进一步改进,增加了许多操作.原来只是在13以下版本下面能用,主要是在13版本下面chrome代码和page下面代码能够直接互调,13版本以后就不可以了,最近考虑到新版Firef ...
- EasyUI在MVC4中需要部分刷新页面时load()后页面变形问题!
最近在使用MVC4与EasUI过程中遇到些容易导致界面变形的问题,纠结了很久,但其实当发现问题在哪里时,倒觉得最终还是自己对MVC4的概念没把握好,OK,show time. 本示例Contact ...
- Activity篇章参考
附上学习这部分知识的时候收集的一些比较好的链接: Task and backStack|Android Developer adb shell dumpsys activity 单个apk多进程 Ac ...
- 用OO方式写键盘字母小游戏
<html> <head> <title>0.0</title> <script> window.onload=functi ...
- java.util.zip.GZIPInputStream.readUByte,Not in GZIP format错误处理
问题一: 使用webclient抓取网页时报错:(GZIPInputStream.java:207) atjava.util.zip.GZIPInputStream.readUShort(GZIPIn ...
- Google Play Services Library update and missing symbol @integer/google_play_services_version
转自http://stackoverflow.com/questions/19843784/google-play-services-library-update-and-missing-symbol ...
- 链表-Add Two Numbers
第一版代码(很挫很罗嗦,不过是第一次做,记录一下成长的脚步!继续努力!) /*struct ListNode { int val; struct ListNode *next; };*/ typede ...
- MySQL加强
MySQL加强 Default Not null Unique Primary key Zerofill primary key auto_increment primary key auto_inc ...
- ebs清除并法管理器所清除的表
In this Document Goal Solution References Applies to: Oracle Concurrent Processing - Version 1 ...
- Python之美[从菜鸟到高手]--生成器之全景分析
yield指令,可以暂停一个函数并返回中间结果.使用该指令的函数将保存执行环境,并且在必要时恢复. 生成器比迭代器更加强大也更加复杂,需要花点功夫好好理解贯通. 看下面一段代码: def gen(): ...