C程序设计语言.pdf_第1页
C程序设计语言.pdf_第2页
C程序设计语言.pdf_第3页
C程序设计语言.pdf_第4页
C程序设计语言.pdf_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1 C程序设计语言程序设计语言 C C 程序设计语言程序设计语言程序设计语言程序设计语言 第第1章 观其大略章 观其大略第第第第1 1章章章章 观其大略观其大略观其大略观其大略 孙志岗孙志岗 sun 2004 12 19A Tutorial Introduction2 Hello WorldHello WorldHello World include include main main printf helloprintf hello world world n n 超级无敌考考你 超级无敌考考你 超级无敌考考你 超级无敌考考你 如何把如何把如何把如何把 hellohello 和和和和 worldworld 分别打印在两行 分别打印在两行 分别打印在两行 分别打印在两行 hello chello c 2004 12 19A Tutorial Introduction3 打印华氏温度与摄氏温度对照表打印华氏温度与摄氏温度对照表打印华氏温度与摄氏温度对照表打印华氏温度与摄氏温度对照表打印华氏温度与摄氏温度对照表打印华氏温度与摄氏温度对照表 计算公式 计算公式 计算公式 计算公式 C C 5 9 5 9 F F 32 32 2004 12 19A Tutorial Introduction4 打印华氏温度与摄氏温度对照表打印华氏温度与摄氏温度对照表打印华氏温度与摄氏温度对照表打印华氏温度与摄氏温度对照表打印华氏温度与摄氏温度对照表打印华氏温度与摄氏温度对照表 include include 对对对对 fahr 0 20 300 fahr 0 20 300 打印华氏温度与摄氏温度对照表打印华氏温度与摄氏温度对照表打印华氏温度与摄氏温度对照表打印华氏温度与摄氏温度对照表 main main intintfahr celsius fahr celsius intintlower upper step lower upper step lower 0 lower 0 温度表的下限温度表的下限温度表的下限温度表的下限 upper 300 upper 300 温度表的上限温度表的上限温度表的上限温度表的上限 step 20 step 20 步长步长步长步长 fahrfahr lower lower whilewhile fahr upper fahr upper celsius 5 fahrcelsius 5 fahr 32 9 32 9 printf printf d d t dt d n n fahr celsius fahr celsius fahr fahr step fahr fahr step fc1 cfc1 c 2 2004 12 19A Tutorial Introduction5 代码风格代码风格代码风格代码风格代码风格代码风格 include include 对对对对 fahr 0 20 300 fahr 0 20 300 打印华氏温度与摄氏温度对照表打印华氏温度与摄氏温度对照表打印华氏温度与摄氏温度对照表打印华氏温度与摄氏温度对照表 main main intintfahr celsius fahr celsius intintlower upper step lower upper step lower 0 lower 0 温度表的下限温度表的下限温度表的下限温度表的下限 upper 300 upper 300 温度表的上限温度表的上限温度表的上限温度表的上限 step 20 step 20 步长步长步长步长 fahrfahr lower lower whilewhile fahr upper fahr upper celsius 5 fahrcelsius 5 fahr 32 9 32 9 printf printf d d t dt d n n fahr celsius fahr celsius fahr fahr step fahr fahr step fc1 cfc1 c 2004 12 19A Tutorial Introduction6 没有代码风格没有代码风格没有代码风格没有代码风格没有代码风格没有代码风格 include include main main intint fahr celsius fahr celsius intint lower upper step lower upper step lower 0 upper 300 step 20 lower 0 upper 300 step 20 fahr lower fahr lower whilewhile fahr upper fahr upper celsius 5 fahrcelsius 5 fahr 32 9 32 9 printf printf d d t dt d n n fahr celsius fahr celsius fahr fahr step fahr fahr step http www ioccc orghttp www ioccc org The International Obfuscated C Code ContestThe International Obfuscated C Code Contest 两个获奖的例子 两个获奖的例子 dance cdance c sqrt csqrt c fc2 cfc2 c 2004 12 19A Tutorial Introduction7 更简单 精确的对照表打印程序更简单 精确的对照表打印程序更简单 精确的对照表打印程序更简单 精确的对照表打印程序更简单 精确的对照表打印程序更简单 精确的对照表打印程序 include include define defineLOWER 0 LOWER 0 表的下限表的下限表的下限表的下限 define defineUPPER 300 UPPER 300 表的上限表的上限表的上限表的上限 define defineSTEP 20 STEP 20 步长步长步长步长 打印华氏打印华氏打印华氏打印华氏 摄氏温度对照表摄氏温度对照表摄氏温度对照表摄氏温度对照表 main main intint fahrfahr forfor fahrfahr LOWER LOWER fahrfahr UPPER UPPER fahrfahr fahrfahr STEP STEP printfprintf 3d 6 1f 3d 6 1f n n fahrfahr 5 0 9 0 5 0 9 0 fahrfahr 32 32 fc3 cfc3 c 2004 12 19A Tutorial Introduction8 字符输入输出字符输入输出字符输入输出字符输入输出字符输入输出字符输入输出 c c getchargetchar 从键盘读入一个字符 赋值给变量从键盘读入一个字符 赋值给变量从键盘读入一个字符 赋值给变量从键盘读入一个字符 赋值给变量c c putchar cputchar c 把把把把c c输出到屏幕输出到屏幕输出到屏幕输出到屏幕 拷贝的基本思想 拷贝的基本思想 拷贝的基本思想 拷贝的基本思想 读一个字符读一个字符读一个字符读一个字符 while while 该字符不是文件结束指示符该字符不是文件结束指示符该字符不是文件结束指示符该字符不是文件结束指示符 输出刚读进的字符输出刚读进的字符输出刚读进的字符输出刚读进的字符 读下一个字符读下一个字符读下一个字符读下一个字符 3 2004 12 19A Tutorial Introduction9 拷贝 拷贝 Copy 拷贝 拷贝 拷贝 拷贝 CopyCopy include include 用于将输入复制到输出的程序 第用于将输入复制到输出的程序 第用于将输入复制到输出的程序 第用于将输入复制到输出的程序 第1 1个版本个版本个版本个版本 main main intintc c c c getchargetchar whilewhile c EOF c EOF putcharputchar c c c c getchargetchar copy1 ccopy1 c 2004 12 19A Tutorial Introduction10 一个更好的版本一个更好的版本一个更好的版本一个更好的版本一个更好的版本一个更好的版本 include include 用于将输入复制到输出的程序 第用于将输入复制到输出的程序 第用于将输入复制到输出的程序 第用于将输入复制到输出的程序 第2 2个版本个版本个版本个版本 main main intintc c while c while c getchargetchar EOF EOF putcharputchar c c copy2 ccopy2 c 2004 12 19A Tutorial Introduction11 计算行数计算行数计算行数计算行数计算行数计算行数 include include 统计输入的行数统计输入的行数统计输入的行数统计输入的行数 main main intint c c longlong nlnl nlnl 0 0 whilewhile c c getchargetchar EOF EOF ifif c c n n nlnl printf dprintf d n n nlnl counter ccounter c 2004 12 19A Tutorial Introduction12 加法器加法器加法器加法器加法器加法器 include include 计算输入的两个整数的和计算输入的两个整数的和计算输入的两个整数的和计算输入的两个整数的和 main main intint a b a b printf Pleaseprintf Please input two integers input two integers scanf d dscanf d d printf Sumprintf Sum d d n n a ba b add cadd c 4 2004 12 19A Tutorial Introduction13 平均分平均分平均分平均分平均分平均分 include include 计算某科成绩的平均值计算某科成绩的平均值计算某科成绩的平均值计算某科成绩的平均值 define define TOTAL NUMBER 10 TOTAL NUMBER 10 总人数总人数总人数总人数 main main floatfloat sum 0 sum 0 score TOTAL NUMBERscore TOTAL NUMBER intint i i printf Inputprintf Input d scores d scores n TOTAL NUMBER n TOTAL NUMBER forfor i 0 i TOTAL NUMBER i i 0 i 0 n 0 intintpower power intint base base intint n n intinti p i p p 1 p 1 forfor i 1 i n i i 1 i n i p p base p p base returnreturn p p power cpower c 2004 12 19A Tutorial Introduction16 power函数的调用 函数的调用 Call powerpower函数的调用 函数的调用 函数的调用 函数的调用 CallCall include include intintpower power intint base base intint n n 测试测试测试测试powerpower函数函数函数函数 main main intintm n m n m power 2 1 m power 2 1 n power n power 3 3 3 3 printf dprintf d d d n n m n m n returnreturn0 0 power cpower c 5 2004 12 19A Tutorial Introduction17 这一章我们

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论