C语言学习笔记[第11天]
五、 运算号、表达式和语句
1.循环简介
/* shoesl.c -- 把鞋码转换成英寸 */
#include <stdio.h>
#define ADJUST 7.31 // 字符常量
int main(void)
{const double SCALE = 0.333;// const 变量double shoe, foot;shoe = 9.0;foot = SCALE * shoe + ADJUST;printf("Shoe size (men's) foot length\n");printf("%10.1f %15.2f inches\n", shoe, foot);return 0;}
//Shoe size (men's) foot length
// 9.0 10.31 inches
/* shoes2.c -- 计算多个不同鞋码对应的脚长 */
#include <stdio.h>
#define ADJUST 7.31 //字符常量
int main(void)
{const double SCALE = 0.333; // const 变量double shoe, foot;printf("Shoe size (men's) foot length\n");shoe = 3.0;while (shoe < 18.5) /* while 循环开始 */{ /* 块开始 */foot = SCALE * shoe + ADJUST;printf("%10.1f %15.2f inches\n", shoe, foot);shoe = shoe + 1.0;} /* 块结束 */printf("If the shoe fits, wear it.\n");return 0;
}//Shoe size (men's) foot length
// 3.0 8.31 inches
// 4.0 8.64 inches
// 5.0 8.97 inches
// 6.0 9.31 inches
//...
// 16.0 12.64 inches
// 17.0 12.97 inches
// 18.0 13.30 inches
2.基本运算符
■=、+、-、*、/
2.1 赋值运算符: =
int ex;
int why;
int zee;
const int TWO = 2;
why = 42;
zee = why;
ex = TWO * (why + zee);
/* golf.c -- 高尔夫锦标赛记分卡 */
#include <stdio.h>
int main(void)
{int jane, tarzan, cheeta;cheeta = tarzan = jane = 68;printf(" cheeta tarzan jane\n");printf("First round score %4d %8d %8d\n", cheeta, tarzan, jane);return 0;
}
// cheeta tarzan jane
//First round score 68 68 68
2.2 加法运算符: +
printf("%d, 4 + 20");
//而不能:
//4 + 20
2.3 减法运算符: -
takehome = 224.00 - 24.00;
2.4 符号运算符: -和+
//标明或改变一个值的代数符号
rock = -12; //使用的负号称为一元运算符
smokey = -rocky;
dozen = +12;
2.5 乘法运算符: *
/* square.c -- 计算1 ~20的平方 */
#include <stdio.h>
int main(void)
{int num = 1;while (num < 21){printf("%4d %6d\n", num, num * num);num = num +1;}return 0;
}
//打印数字1 ~ 20及其平方
■指数增长
/* wheat.c -- 指数增长 */
#include <stdio.h>
#define SQUARES 64 // 棋盘中的方格数
int main(void)
{const double CROP = 2E16; // 世界小麦年产谷粒数double current, total;int count = 1;printf("square grains total ");printf("fraction of \n");printf(" added grains ");printf("world total\n");total = current = 1.0; /* 从1颗谷粒开始 */printf("%4d %13.2e %12.2e %12.2e\n", count, current,total, total / CROP);while (count < SQUARES){count = count +1;current = 2.0 * current; /* 下一个方格谷粒翻倍 */total = total + current; /* 更新总数 */printf("%4d %13.2e %12.2e %12.2e\n", count, current, total, total/CROP);}printf("That's all.\n");return 0;
}
//square grains total fraction of
// added grains world total
// 1 1.00e+000 1.00e+000 5.00e-017
// 2 2.00e+000 3.00e+000 1.50e-016
// 3 4.00e+000 7.00e+000 3.50e-016
// 4 8.00e+000 1.50e+001 7.50e-016
// 5 1.60e+001 3.10e+001 1.55e-015
// 6 3.20e+001 6.30e+001 3.15e-015
// 7 6.40e+001 1.27e+002 6.35e-015
// 8 1.28e+002 2.55e+002 1.27e-014
// 9 2.56e+002 5.11e+002 2.55e-014
// 10 5.12e+002 1.02e+003 5.12e-014
//...
// 55 1.80e+016 3.60e+016 1.80e+000
//...
// 64 9.22e+018 1.84e+019 9.22e+002
//That's all.
C语言学习笔记[第11天]相关推荐
- Go语言学习笔记【11】 数据结构之稀疏矩阵、队列、栈
[声明] 非完全原创,部分内容来自于学习其他人的理论和B站视频.如果有侵权,请联系我,可以立即删除掉. 一.稀疏矩阵 若数值为0的元素数目远远多于非0元素的数目,并且非0元素分布没有规律时,则称该矩阵 ...
- c语言中void arrout,c语言学习笔记(数组、函数
<c语言学习笔记(数组.函数>由会员分享,可在线阅读,更多相关<c语言学习笔记(数组.函数(53页珍藏版)>请在人人文库网上搜索. 1.数组2010-3-29 22:40一维数 ...
- go get 拉取指定版本_go语言学习笔记-基础知识-3
相关文档 go语言学习笔记-目录 1.简介 1.1 什么是GO Go 是一个开源的编程语言,它能让构造简单.可靠且高效的软件变得容易.Go是从2007年末由Robert Griesemer, Rob ...
- R语言学习笔记(1~3)
R语言学习笔记(1~3) 一.R语言介绍 x <- rnorm(5) 创建了一个名为x的向量对象,它包含5个来自标准正态分布的随机偏差. 1.1 注释 由符号#开头. #函数c()以向量的形式输 ...
- 【Go语言 · 学习笔记】
文章目录 Go语言 · 学习笔记 一.Go包管理 1. 什么是Go语言中的包 2. 包的命名 3. main包 4. 导入包 5. 远程包导入 6. 命名导入 7. 包的init函数 二.Go开发工具 ...
- c语言计算时钟的夹角不用if,C语言学习笔记——计算时钟的夹角
C语言学习笔记--计算时钟的夹角 题目内容: 钟面上的时针和分针之间的夹角总是在 0 -180之间 ( 包括 0 和180 ) .举例来说,在十二点的时候两针之间的夹角为 0 ,而在六点的时候夹角为1 ...
- R语言学习笔记 07 Probit、Logistic回归
R语言学习笔记 文章目录 R语言学习笔记 probit回归 factor()和as.factor() relevel() 案例11.4复刻 glm函数 整理变量 回归:Logistic和Probit- ...
- Lawliet|C语言学习笔记5——循环结构
C语言学习笔记--循环结构 1.求1+2+3+-+100 #include<stdio.h> int main() {int i=1,sum=0; //定义变量i的初值为1,sum的初值为 ...
- Lawliet|C语言学习笔记2——变量/数据类型/表达式
C语言学习笔记2--认识C语言1 1.变量 a.变量的命名 <类型名称><变量名称> 存放数据的一个地方,用于参与后续的运算. 变量命名的规则:只能由字母.数字和下划线组成,且 ...
最新文章
- 【概率论】1-4:事件的的并集(Union of Events and Statical Swindles)
- 【译】Byzantine Fault Tolerance in Proof-of-stake protocols
- 2021中国餐饮营销力白皮书
- mysql查询字段变慢,MySQL Query IN()子句在索引列上变慢
- 数据库报错SELECT list is not in GROUP BY clause and contains nonaggregated col
- 常见移动机器人轮直径校准实现(ROS)方法
- ---perl 模块安装方法
- 邮箱大师与微软Acompli功能评测
- js定时刷新页面数据
- 编译ffmpeg报错ffmpeg yasm not found, use --disable-yasm for a crippled build
- sql根据身份证计算年龄
- Springboot开关柜综合监测信息查询系统毕业设计-附源码191550
- 【博学谷学习记录】超强总结,用心分享 | JavaString类知识要点总结
- Selenium中的EC模块
- 手游族迎来360手机卫士神助攻 玩家免打扰尽情发育
- HBuilderX软件
- 【JS】数据结构之树结构
- MHz 和 Mbps的区别
- Rule of lawlessness 南非法治之战 | 经济学人中英双语对照精读笔记
- 深度学习实战——手写数字识别