c程序设计授课内容

上传人:第*** 文档编号:32684249 上传时间:2018-02-12 格式:DOC 页数:13 大小:302.50KB
返回 下载 相关 举报
c程序设计授课内容_第1页
第1页 / 共13页
c程序设计授课内容_第2页
第2页 / 共13页
c程序设计授课内容_第3页
第3页 / 共13页
c程序设计授课内容_第4页
第4页 / 共13页
c程序设计授课内容_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《c程序设计授课内容》由会员分享,可在线阅读,更多相关《c程序设计授课内容(13页珍藏版)》请在金锄头文库上搜索。

1、C 程序设计第 1 页C 程序设计授课内容一、形成:1. 概念:指令(Instruction) :规定计算机操作类型及操作数地址的一组字符。程序(Program):为解决某一问题而设计的一系列指令。2. 程序设计语言:最高级:Ada、Modula-2、Pascal、COBOL、FORTRAN、BASIC。中级:C、FORTH、宏汇编语言。最低级:汇编语言。3. C 语言形成:参课件。ALGOL 60 1960CPL 11963 BCPL 21967Matin RichardsB1970Ken ThompsonC1972-73Dennis M. RitchieBrian W. Kernighan

2、 & Dennis M. RitchieThe C Programming Language, Prentice-Hall, 1978。1988 年修改后再版。4. 带类的 C,可视化的 C:Visual C+、C# ,C+ Builder5. 特点:参考课本内容。又参。6. C 语言关键字(Keywords):auto break case charconst continue default dodouble else enum externfloat for goto ifint long register returnshort signed sizeof staticstruct s

3、witch typedef unionunsigned void volatile while例 1:Hello World!7. 编译程序(Compiler):源程序(*.c) 目标程序(*.obj) 可执行程序(*.exe)。开发过 程参。二、常量、变量和表达式:1. 常量(Constant):参课件。“this is a test”、 a、36、0、-8、3.1416、-5.6、3e8、.35、200.、0357、0x3e。后缀字符:L 3、U 4、F 5。转义字符(Backslash Character Constants):Code Meaning ASCII码 Code Meani

4、ng ASCII 码b Backspace 8 Single quote character 39f Form feed 12 Backslash 92n New line 10 v Vertical tabr Carriage return 13 a Audible alert (bell)t Horizontal tab 9 o Octal constant1 Combined Programming Language2 Basic Combined Programming Language3 long4 unsigned5 认为是单精度C 程序设计第 2 页” Double quote

5、34 x Hexadecimal constant? Question mark 0 Null2. 变量(Variable) :标识符( Identifier6)名(Rules for Identifiers) : First character must be an alphabet (or underscore). Must consist of only letters, digits or underscore. Only first 31 characters are significant. Cannot use a keyword. Must not contain white

6、space7. 正确名: count、test23 、high_balance ;不正确名:1count、hi! there、high.balance、else。数据类型(Data Types):参课件。Type Bit Width Rangechar 8 0 to 255int 16 -32768 to 32767float 32 3.4E-38 to 3.4E+38double 64 1.7E-308 to 1.7E+308void 0 valueless类型修饰符(Qualifier):signed 、unsigned 、long、short。3. 运算符及表达式(Operators a

7、nd Expressions): 算术运算符(Arithmetic operators):+、-、*、/、% 8。 自增及自减运算符(Increment and decrement operators):+、-。 算术运算符及自增、自减运算符的优先级(由高到低) :+、- ;- (一元减);*、/、%;+、- 。 关系运算符(Relational operators):、=、 、=、5) printf(“%d”, x);else printf(“%dn”, x-);A.7 和 5B.6 和 4C.7 和 4D.6 和 4 多分支条件语句:if(expression)statement;else

8、 if(expression)statement;else if(expression)statement;elsestatement;例 3:猜数程 序。?运算符:参见表达式运 算符。例:if/else 结构:x=10;if (x9) y=100;else y=200;?运算符结构:x=10;y=x9 ? 100 : 200;?运算符代替 if/else 结构的限制:目标必须是单表达式,不是另一条 C 语句。但在表达式中,允许使用一个或多个函数调用。例(二级) :若 w,x,y,z,m 均为 int 型变量,则执行下面语句后的 m 值是( vii) 。w=1; x=2; y=3; z=4;m

9、=(wmain(void)/* This prints “this is a test” left-justified in 20-character field. */printf(“%-20s”, “this is a test”);/* This prints a float with 3 decimal places in a 10-character field.The output will be “ 12. 235” */printf(“%10.3f”, 12.234657);return 0;3. putchar 函数: 格式:int putchar(int ch) putch

10、ar( )的原型在 stdio.h 中。C 程序设计第 7 页 putchar( )宏将包含在 ch 的最低有效字节中的字符写到 stdout 中。4. scanf 函数: 格式:int scanf(const char *format, arg-list) scanf( )的原型在 stdio.h 中。 scanf( )函数是一个通用输入例程,它读取流 stdin。它可读取所有内部数据类型,并自动将它们转换成适当的内部格式。 由 format 所指的控制字符串由 3 类字符构成:格式说明符;空白间隔字符;非空白间隔字符。 scanf( )格式代码:Code Meaning%c Read a

11、single character%d Read a decimal integer%i Read a decimal integer%e Read a floating-point number%f Read a floating-point number%h Read a short integer%o Read an octal number%s Read a string%x Read a hexadecimal number%p Read a pointer%n Receive an integer value equal to the number of characters rea

12、d so far. 所有用于通过 scanf( )接收值的变量必须通过其地址传递。例:(二级) :在 scanf 函数调用语句中,可以在格式字符和% 号之间加一星号,它的作用是 xii;当输入以下数据:10203040(此处每个数据之间有两个空格) ,下面语句的执行结果是 xiii。int a1, a2, a3;scanf(“%d%*d%d%d”, 例:scanf(“%st%s”, (给定输入流 10t20)例(二级) :执行输入语句“scanf(“x=%c, y=%d”, ”,要使字符型变量 x 的值为A、整型变量 y 的值为 12,则从键盘上正确的输入是( xiv) 。A. A/ B. A

13、/ C. x=A/ D. x=A, y=12/12/ 12/ y=12/说明:备选答案中的“/”表示回车换行键。5. getchar 函数: 格式:int getchar(void) getchar( )的原型在 stdio.h 中。 getchar( )宏返回 stdin 中的下一个字符。字符是作为转换成整数的 unsigned char读取。6. pow 函数: 格式:double pow(double base, double exp)C 程序设计第 8 页 pow( )的原型在 math.h 中。 pow( )函数返回 baseexp 的值。如果 base 等于 0 且 exp 小于等

14、于 0,那么出现范围错误。例:如下程序打印 12 的前 11 个方幂。7. cos 函数: 格式:double cos(double arg) cos( )的原型在 math.h 中。 cos( )函数返回 arg 的余弦。arg 的值必须用弧度表示。返回值的范围在 -11 之间。例:如下程序打印值-11 的余弦,每次增加 0.1。8. fabs 函数: 格式:double fabs(double num) fabs( )的原型在 math.h 中。 fabs( )函数返回 num 的绝对值。例:如下程序在屏幕上打印“1.0 1.0” 。9.十一、ANSIC 文件系统: 常见函数:Name F

15、unctionfopen() Opens a streamfclose() Closes a streamputc() Writes a character to a streamgetc() Reads a charater from a streamfseek() Seeks to specified byte in a streamfprintf() Is to a stream what printf() is to the consolefscanf() Is to a stream what scanf() is to the consolefeof() Returns true

16、if end of file is reachedferror() Returns true if an error has occurredrewind() Resets the file position locator to the beginning of the fileremove() Erases a filefopen() 函数中 mode 的合法值:Mode Meaning“r” Open a text file for reading“w” Create a text file for writing“a” Append to a text file“rb” Open a binary file f

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 中学教育 > 职业教育

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号