文档详情

第1章 C语言概述(第1次课).ppt

发布:2017-08-10约3.25千字共16页下载文档
文本预览下载声明
C格式注意事项 通常用小写字母,大小写有区别 可使用空行和空格 常用锯齿形书写格式 每层{ }对齐 * * C语言的产生 C语言特点 简单的C语言程序介绍 第1章 C语言概述 产生 时间:1973 地点:美国贝尔实验室 目的:UNIX操作系统 设计人: Ken.Thompson和Dennis.M.Ritchie C标准 1990年国际标准的ANSI C(American National Standards Institute ) 对B的精练,改写UNIX操作系统 对BCPL的进一步简化,编写了UNIX操作系统。 对CPL作了简化 规模大,难以实现 面向问题的高级语言,难以实现硬件操作 C语言 1973 B语言 1970 BCPL 1967 CPL 1963 ALGOL 60 1960 C语言的特点(P2) 语言简洁、紧凑、灵活(32个关键字,小写字母) 运算符丰富 数据类型丰富(P37) 程序设计结构化、模块化(函数FUNCTION) 语法限制不太严格,程序设计自由度大 C语言能进行位(bit)操作,直接对硬件进行操作 生成目标代码质量高,程序执行效率高 可移植性好 #include stdio.h void main() { printf(This is a C program.\n); } 编译预处理 语句 运行结果: main函数 简单的C语言程序介绍 例1.1 输出一行信息 This is a C program. Press any key to continue_ 一对花括号 例1.2 求两个整数的和 #include stdio.h /*This is the main function*/ void main() { int a,b,sum; a=123; b=456; sum=a+b; /*求a 、b的和*/ printf(sum=%d\n,sum); } 运行结果: 执行部分,实现功能 sum=579 Press any key to continue_ 声明部分,定义变量 注释 例1.2 求两个整数的和 #include stdio.h /*This is the main function*/ void main() { int a,b,sum; a=123; b=456; sum=a+b; /*求a 、b的和*/ printf(sum=%d\n,sum); } printf(a=%d,b=%d\n,a,b); 运行结果: a=123,b=456 sum=579 _ #include stdio.h void main() { int a,b,c; scanf(%d,%d,a,b); if(ab) c=a; else c=b; printf(max=%d\n,c); } 例 求 任意整数a和 b的最大值 输入变量a,b的值 求出a,b最大值=c 输出结果c start end 主要步骤: 体会运行过程 #include stdio.h void main() { float x,y,s; scanf(%f,%f,x,y); s=x*y; printf(Area=%f\n,s); } 练习:求长方形的面积(已知长和宽都是实数) 输入长=x 输入宽=y 求面积=s 输出结果s start end 例1.3 求 a和 b的最大值 输入变量a,b的值 求出a,b最大值 输出结果 start end 输入变量a,b的值 a=x ,b=y 求出x,y最大值=z z=c main() max() main() 输出结果c start end #include stdio.h void main() { int max(int x,int y); int a,b,c; scanf(%d,%d,a,b); c=max(a,b); printf(max=%d\n,c); } 例1.3 求 a和 b的最大值 /* This function calculates the max of x and y */ int max(int x,int y) { int z; if(xy) z=x; else z=y; return(z); } /* 函数声明 */ /* 函数调用
显示全部
相似文档