文章标题
来源:互联网 发布:2016淘宝开学季活动 编辑:程序博客网 时间:2024/05/16 10:34
# C语言if…else语句
—–
16340287
数据科学与计算机学院
—–
目录
[TOC]
—–
1.一个if ... else语句在C编程语言的语法:
if(boolean_expression)
{
/* statement(s) will execute if the boolean expression is true */
}
else
{
/* statement(s) will execute if the boolean expression is false */
}
如果布尔表达式的计算结果为true,则if块中的代码将被执行,否则else块的代码将被执行。
作为真正的C编程语言承担任何非零和非空值,如果它是零或空(null),那么它被假设为假值。
2.if … else例子
#include
int main ()
{
/* local variable definition */
int a = 100;
/* check the boolean condition */
if( a < 20 )
{
/* if condition is true then print the following */
printf(“a is less than 20\n” );
}
else
{
/* if condition is false then print the following */
printf(“a is not less than 20\n” );
}
printf(“value of a is : %d\n”, a);
return 0;
}
上面的代码编译和执行时,它会产生以下结果:
a is not less than 20;
value of a is : 100
3.if…else if…else语句需牢记几点。
a.An if can have zero or one else’s and it must come after any else if’s.
b. An if can have zero to many else if’s and they must come before the else.
c. Once an else if succeeds, none of the remaining else if’s or else’s will be tested.
在此强加一个公式
R^n - 1 = R^n - 1^n = (R-1)(R^(n-1) + R^(n-2) + … + R^0) = (R-1)R^(n-1) + (R-1) R^(n-2) + … + (R-1)R^0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- ImageView属性
- Android:联系人Contacts之ContentResolver query 参数详解
- Python模块学习:threading 多线程控制和处理
- MAC 更新 PHP 指南 以及 PHP常用命令示例
- 深入理解Java 8 Lambda(语言篇——lambda,方法引用,目标类型和默认方法)
- 文章标题
- 第7周项目1-建立顺序串的算法库
- [Java 8] (10) 使用Lambda完成函数组合,Map-Reduce以及并行化
- JSP网页处理过程
- Android TabLayout的简单用法
- 第五周项目三 括号的匹配
- 详解Java 8中Stream类型的“懒”操作
- 微信公众号【用户分组管理-web页面】
- Android中surface,surfaceview,sufaceholder以及surface客户端的关系