<stdbool.h>的使用
转载:
1.https://www.cnblogs.com/jediael/archive/2013/02/03/4304259.html
2.https://zhidao.baidu.com/question/561939817.html
(1)使用了<stdbool.h>后,可使用true和false来表示真假。
(2)在循环语句中进行变量声明是C99中才有的,因此编译时显式指明 gcc -std=c99 prime.c
[lujinhong@lujinhong chapter9]$ gcc prime.c
prime.c: In function ‘isPrimeâ€:
prime.c:23: error: ‘for†loop initial declarations are only allowed in C99 mode
prime.c:23: note: use option -std=c99 or -std=gnu99 to compile your code
[lujinhong@lujinhong chapter9]$ gcc -std=c99 prime.c
/**********************************************************
*purpose:
* 判断一个整数是否素数。
*method:
* 从2开始,至这个整数的平方根,若能整除其中任何一个则非素数并返回。
***********************************************************/ #include <stdio.h>
#include <stdbool.h> bool isPrime(int n); int main(void){ int n; printf("Please enter a digit to test is it a prime or not: ");
scanf("%d",&n);
if(isPrime(n))
printf("%d is a prime.\n", n);
else
printf("%d is not a prime.\n", n); return 0;
} bool isPrime(int n){ for(int i=2; i*i<n; i++){
if(n%2==0) return false;
}
return true;
}
bool 是C++中的关键字,C中不支持
所以C99标准中百引入了头文件 stdbool.h,包含了四个用度于布尔型问的预定义宏
#define true 1
#define false 0
#define bool _Bool
typdef int _Bool
看看 stdbool.h 的内容就知道了。答
is_even函数是用来判断你输入的整数是否是偶版数权。如果是则返回true,否则返回false
如:输入10返回true 11返回false
10是偶数,11是奇数
<stdbool.h>的使用的更多相关文章
- <form:select>的使用
最近在学习springMVC,用到了<form:select>标签,使用发过程中遇到了些问题,现在记录下,以防忘记. 我jsp页面是这样的: <%@ page language=&q ...
- dijit.form.Select 基本用法
dijit.form.Select 1)创建: var division = new dijit.form.Select({ id: "Division",//id必须唯一 nam ...
- dijit样式定制(二)dijit.form.Select与dijit.form.NumberSpinner
dijit.form.Select: Select的样式位于Claro/form/Select.less中,Select主要通过table来布局,下图可以看到Select的布局结构 介绍几个主要的cl ...
- 关于<form:select>
今天写基于SSM框架的程序,用到了<form:select>.由于一开始遇到了问题,所以在这里加以记录,供以后查看. 直接看jsp页面的代码 <%@ page language=&q ...
- form:select form:options 标签数据回显
在jsp页面中经常会使用到 form:select form:options 遍历后台List集合生成 select 下拉选择器,但是 form:options 标签并没有提供一个可以回显数据的属性. ...
- <form:select>
<form:select path="classification" class="input-medium"> <form:option v ...
- 前端 form select js处理
1.代码如下 function initializeSelect(data) { var area = $("#ServiceName"); area.find("opt ...
- form:select的内容
https://blog.csdn.net/ccclych1/article/details/88395650
- HTML:form表单总结,input,select,option,textarea,label
<form>标签是块级元素. form标签的标准属性有id,class,style,title,lang,xml:lang. 表单能够包含input元素(包含button,checkbox ...
- select标签 禁止选择但又能通过序列化form表单传值到后台
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁止选择但又能通过序列化form表单传值到后台,但是当我们使用disabled="disabled"时发现,无法序列化 ...
随机推荐
- 总结删除文件或文件夹的7种方法-JAVA IO基础总结第4篇
本文是Java IO总结系列篇的第4篇,前篇的访问地址如下: 总结java中创建并写文件的5种方式-JAVA IO基础总结第一篇 总结java从文件中读取数据的6种方法-JAVA IO基础总结第二篇 ...
- android开发之gridView的一些属性。(项目经验总结)
1.android:numColumns="auto_fit" //GridView的列数设置为自动 2.android:columnWidth="90dp &quo ...
- Unity动态绑定按钮触发方法
在使用unity制作UI的过程中,基本都需要接触到按钮,然后按钮要起作用的话,那么就需要为按钮绑定响应方法. 为按钮绑定触发的方法,我知道的有两种方法,第一种:手动使用unityEditor 绑定,另 ...
- C++——百分率
代码如下: #include <iostream> #include <cmath> using namespace std; int main() { double a; c ...
- jQuery 如何实现 模糊搜索
如何实现 模糊搜索 当我们浏览网页的时候,通常能看到搜索栏,这大大的提高了我们获取数据的目的性.那如何去实现一个简单的模糊搜索 框呢,以下案例获取能给你一点思路. 以下案例,可以实现当按键按下时,自动 ...
- 写Junit测试时用Autowired注入的类实例始终为空怎么解?
踩坑半天多,终于在网上寻觅到了解决方案,特此分享一下. 重要前提:src/main/java下的根包名必须和src/test/main的根包名完全一致,否则就会发生死活不能注入的情况,要继续进行下面的 ...
- SpringBoot2 引入 Aop
一步小心就掉进坑里面了:SpringBoot2 引入 Aop 不生效 SpringBoot2.1.3版本 首先,引入依赖 <!--面向切面--> <dependency> &l ...
- Java模拟实现扫雷功能
//棋子 public class Chess { private boolean isBoomb=false; private int id;//下标 //点击方法 public int click ...
- 大量数据也不在话下,Spring Batch并行处理四种模式初探
1 前言 欢迎访问南瓜慢说 www.pkslow.com获取更多精彩文章! Spring相关文章:Springboot-Cloud 前面写了一篇文章<通过例子讲解Spring Batch入门,优 ...
- pycharm代码中批量粘贴内容的快捷键
windows电脑中,竖向批量复制的快捷键:Alt