C程序设计语言

高级语言的含义:what to do , how to do

二元一次方程: ax2+bx+c=0

手工求解法:1)a=0 1.1)b=0 1.1.1)c=0 任意数

1.1.2)c<>0 无解

1.2)b<>0 x=-(c/b)

2) a<>0 x1=(-b+sqrt(b2-4a*c))/(2*a)

x2=(-b-sqrt(b2-4a*c))/(2*a)

计算机求解法:输入a b c的值,通过计算输出x解的结果

1)a、b、c为任意值,由键盘输入

2)分析判断:算法部分

3)输出:x的结果解

4)算法语句书写规则:数据类型、运算符、表达式、函数

Chapter 1: Types, Operators, and Expressions

类型、运算符和表达式

§2.1 Variable Names (变量名,概念)

·letters (include “_”) and digitals, begin with letter

·upper case and lower case letters are DISTINCT

·keywords like if, else, int, float, etc.,are reserved

Legal variable names (or identifier):

sum, average, class, day, month, student_name, _above,

lotus_1_2_3, basic, The_C_Programming_Language

Illegal variable names:

M.D.Join, $123, #33, 3D64, a>b

§2.2 Data Types and Sizes (数据类型和大小)

☆Basic data types in C:

·char a single byte, holding ONE character (1 byte)

·int an integer (2 or 4 bytes)

·float single-precision floating point (4 bytes)

·double double-precision floating point (8 bytes)

所有的基本类型都是“数值类型”,其数据都可参与数值运算。

☆Some qualifiers can be applied to these basic types:

·short and long apply to integers:

short int sh or short sh (int can be omitted)

long int counter or long counter

·signed or unsigned may be applied to char or ANY integer

signed can ALWAYS be omitted

signed char (or char) values between -128~127 unsigned char values between 0~255

signed int (or int) values between -2n-1~2n-1-1

unsigned int values between 0~2n-1

☆function sizeof return the size of the type or variable.

char ch;

sizeof(char) = 1 or sizeof(ch) = 1 (byte)

§2.3 Constants (常量)

☆int constant

·int: 123, -456

·long: 123456789l or 123456789L

·unsigned int: 123u or 123U

·unsigned long: 123456789ul or 123456789UL

·octal(八进制): A leading 0 on an integer constant

e.g. 037 (= 31 in decimal)

·Hexadecimal(十六进制): A leading 0x or 0X on an int constant

e.g. 0x1f or 0X1F (= 31 in decimal)

☆float or double constant

·float or double: 123.4 or 1e-2

·float ONLY: 123.4f or 123.4F

☆char constant: ‘x’, ‘0’, ‘\n’, ‘\013’, ‘\xb’, ‘\x7’

·The complete set of escape sequences:

\a alert(bell) character \\ backslash

\b backspace \? question mark

\f formfeed \’ single quote

\n newline \” double quote

\r carriage return \ooo octal number

\t horizontal tab \xhh hex number

\v vertical tab

·’\0’ represents null character, with value zero.

☆string constant:

·“I am a string” I a m a s t r i n g\0

·“” null string \0

·function strlen(s) return the length of its character string argument s, excluding the terminal ‘\0’.

/* strlen: return length of s */

int strlen(char s[])

{

int i;

i = 0;

while (s[i] != 0)

i++;

return(i);

}

☆the difference between ‘x’ and “x”:

·‘x’ is a integer, used to produce the numeric value of the letter x in the machine’s character set(always ASCII-120).

x

·“x” is an array of characters that contains one character (the letter x) and a ‘\0’.

x \0

☆symbolic constant(符号常量)

#define  BELL ‘\007’ /* ASCII bell character */

#define PRICE 30

☆enumeration constant(枚举常量):

·enum boolean {NO, YES}; /* No = 0, and YES = 1 */

·enum escapes {BELL = ‘\a’, BACKSPACE = ‘\b’, TAB = ‘\t’,

NEWLINE = ‘\n’, VTAB = ‘\v’, RETURN = ‘\r’};

·enum months {JAN = 1, FEB, MAR, APR, MAY, JUN, JUL, AUG,

SEP,OCT,NOV,DEC}; /*FEB is 2, MAR is 3, etc.*/

§2.4 Declarations (变量定义)

☆All variables MUST be declared before use. 先定义,后使用

☆ Declaration form: type var1, var2, …, varN;

int lower, upper, step;

char c, line[1000];

Could equally well be written as

int  lower;

int upper;

int step;

char c;

char line[1000];

☆ A variable may also be initialized in its declaration.

·general form:

char esc = ‘\\’;

int i = 0, j, k=1, m;

int  limit = MAXLINE+1;

float eps = 1.0e-5;

·const form: specify that the value will not be changed.

const double pi = 3.1415926535;

const char message[] = “warning:”;

§2.5 Arithmetic Operators (算术运算符)

·binary arithmetic operators: +, -, *, /, %(modulus op.) .

·+, -, *, and / can be applied to any basic type, but %

can’t be applied to float and double.

·ATTENTION(注意)!!!

float(double)/float(double) => float(double)

float(double)/int => float(double)

int/float(double) => float(double)

int/int => int

e.g. 10.0/4 = 2.5, but 10/4 = 2 -10/4 = -2

·10%3 = 1 -10%3 = -1 10 % 2 = 0

N = (N/m)*m + N%m where, N and m are both int.

·Precedence & associativity(优先级和结合性):

“*” = “/” = “%” > “+” = “-”

All arithmetic operators associate left to right.

e.g. 3 + 5 * 2 - 10 / 4 % 3  <=> 3 + (5 * 2) - 10 / 4 % 3

=> 3 + 10 - 10 / 4 % 3 <=> (3 + 10) - 10 / 4 % 3

=> 13 - 10 / 4 % 3 <=> 13 - (10 / 4) % 3

=> 13 - 2 % 3 <=> 13 - (2%3)

=> 13 - 2 <=> (13 - 2)

=> 11 <=> 11

·Arithmetic expression_r(算术表达式):

用算术运算符和括号将运算对象(操作数)连接起来的、符合C语法规则的式子,称算术表达式。运算对象包括常量、变量、函数等。e.g.:

a * b / c - 1.5 + ‘a’

运算的结果即为算术表达式的值。

§2.6 Assignment Operators and Expressions赋值运算符和表达式

·Assignment operator: “=”

e.g.: x = 12 “=” 号左边必须是一个变量!

·Compound assignment operators(复合的赋值运算符): op=

where, op is one of

+, -, *, /, %, <>, &, ^, |

expr1 op= expr2 <==> expr1 = (expr1) op (expr2)

where, expr1 must be a variable.

e.g.:

a += 3 <==> a = a + 3

x *= y+8 <==> x = x * (y+8)

x %= 3 <==> x = x % 3

·由赋值运算符将一个变量和一个表达式连接起来的式子称为“赋值表达式”。

(此“表达式”也可以是一个赋值表达式)

·赋值表达式的值就是被赋值的变量的值。

·赋值运算符的按照“自右向左”的结合顺序。

e.g.: a = 3 表达式的值 => 3

a = (b = 5) <==> a = b = 5 => 5

a = b = c = 5 => 5

a = 5 + (c=6) => 11

a = (b=4) + (c=6) => 10

a = (b=10) / (c=2) => 5

a += a -= a*a <==> a += (a -= (a*a))

如果a的初始值为12, 则

(1) 先算a*a = 12*12 = 144, 此时a = 12

(2) 再算a -= 144, 即 a=a-144=12-144=-132, 此时,a = -132

(3) 然后算 a += -132, 即 a = a+(-132)=(-132)+(-132)=-264

c语言x1=abc什么意思,c语言起步(课件)2.1相关推荐

  1. 编写一个c语言 输入abc 输出最大数,C语言 输入abc,求最大数

    满意答案 wiahru 2014.01.12 采纳率:50%    等级:12 已帮助:9318人 #include int max(int a,int b){ return a > b ? a ...

  2. C语言代码示范与讲解+C语言编程规范及基础语法+编程实战

    上一篇文章:C语言程序设计概述+C语言简介+算法概述 C语言代码示范与讲解+C语言编程规范及基础语法+编程实战 一:代码示范集加讲解 1.C语言第一个代码:打印"This is the fi ...

  3. c语言输入后没答案,C语言章节习题及答案(无指针)解读.doc

    C语言章节习题及答案(无指针)解读 <C程序设计>复习题集 第2章 基础概念 一.选择题(在下列各题的A).B).C).D)四个选项中,只有一个选项是正确的) 2.1以下叙述中正确的是 A ...

  4. c语言既适合于开发,C语言试题及答案 (1)

    C语言试题及答案 (1) 文章<C语言试题及答案 (1)>是由[作文仓库]的会员[我这么冷你怕不怕]为大家整理并分享的,仅供大家参考,欢迎阅读! 第1章 C语言概述习题 1. 单项选择题 ...

  5. 北京科技大学C语言程序设计,北京科技大学《C语言》第1章.ppt

    <北京科技大学<C语言>第1章.ppt>由会员分享,可在线阅读,更多相关<北京科技大学<C语言>第1章.ppt(36页珍藏版)>请在装配图网上搜索. 1 ...

  6. c语言程序设计教程ppt,《C语言程序设计教程》.ppt

    <<C语言程序设计教程>.ppt>由会员分享,可在线阅读,更多相关<<C语言程序设计教程>.ppt(30页珍藏版)>请在装配图网上搜索. 1.第1章 预 ...

  7. c语言第1章ppt,c语言第1章课件.ppt

    <c语言第1章课件.ppt>由会员分享,可在线阅读,更多相关<c语言第1章课件.ppt(30页珍藏版)>请在人人文库网上搜索. 1.第1章 C语言概述,计算机中心,C 语言程序 ...

  8. c语言八大数据基本类型,C语言中基本的数据类型有哪些

    C语言中基本的数据类型有哪些 发布时间:2020-11-26 15:10:13 来源:亿速云 阅读:76 作者:Leah 本篇文章给大家分享的是有关C语言中基本的数据类型有哪些,小编觉得挺实用的,因此 ...

  9. 兰州大学C语言程序设计课程作业,兰州大学C语言程序设计课程作业1附答案.doc...

    兰州大学C语言程序设计课程作业1附答案.doc C 语言程序设计课程作业语言程序设计课程作业_A 历次成绩 完成时间 查看详情 1.0.0 2015-11-21 091531 2.0.0 2015-1 ...

最新文章

  1. 什么地方容易刷出ak_男人会用什么理由拒绝表白?
  2. Windows API入门系列之六 -自己实现MessageBox
  3. CentOS 6.2安装
  4. [pytorch、学习] - 5.7 使用重复元素的网络(VGG)
  5. B-Tree及其建立过程
  6. C语言二叉树字符统计,C语言实现二叉树-利用二叉树统计单词数目
  7. Mac软件损坏,无法打开,允许任何来源后依旧损坏
  8. android整理的一些零散笔记
  9. nginx post请求超时_nginx的重试机制以及nginx常用的超时配置说明
  10. C#/.NET整数的三种强制类型转换(int)、Convert.ToInt32()、int.Parse()的区别
  11. 大前端技术选型 Native原生iOS, Android, React-Native, Flutter, 微信小程序, HTML5
  12. 如何umount一个busy的目录?
  13. IDEA查看Java源码技巧
  14. 一文彻底搞懂加密、数字签名和数字证书,看不懂你打我!
  15. python中国大学慕课平台_乐学Python,中国大学MOOC(慕课)答案公众号搜题
  16. 高德api只显示省级地图
  17. ROS2 C++ Subscriber Publisher 订阅发布例子
  18. activity has leaked window
  19. java 2048思路_Java版2048
  20. 项目启动报错 Error running ‘xxxApplication‘;Command line is too long,Shoerten command line for........

热门文章

  1. 域名解析服务查询工具dnstracer
  2. Arduino可穿戴开发入门教程Windows平台下安装Arduino IDE
  3. Xcode 7.0正式版发布了
  4. mysql更改可执行文件路径_Mysql 服务 1067 错误 的解决方法:修改mysql可执行文件路径...
  5. python课后题答案第五章_Python语言程序设计(美-梁勇)第5章习题解答
  6. php面向对象mysqli,php+mysqli使用面向对象方式更新数据库实例
  7. 输出区间内素数的c语言程序,1137C/C++经典程序训练7---求某个范围内的所有素数...
  8. python requests cookies请求_python的requests库怎么发送带cookies的请求
  9. 在虚幻UE4中不同VR头盔的FOV和分屏处理
  10. 数据结构 排序 java_Java数据结构之排序---希尔排序