C程序设计语言.pdf
上传人:qw****27 上传时间:2024-09-12 格式:PDF 页数:5 大小:181KB 金币:15 举报 版权申诉
预览加载中,请您耐心等待几秒...

C程序设计语言.pdf

C程序设计语言.pdf

预览

在线预览结束,喜欢就下载吧,查找使用更方便

15 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

Hello,World#include<stdio.h>main()C程序设计语言{printf("hello,world\n");}第1章章观观其大略其大略„超级无敌考考你:孙志岗如何把“hello”和“world”分别打印在两行?sun@hit.edu.cnhttp://sunner.cnhello.c2004-12-19ATutorialIntroduction2打印华氏温度与摄氏温度对照表打印华氏温度与摄氏温度对照表#include<stdio.h>„计算公式:/*对fahr=0,20,...,300C=(5/9)(F-32)打印华氏温度与摄氏温*/度对照表main(){intfahr,celsius;intlower,upper,step;lower=0;/*温度表的下限*/upper=300;/*温度表的上限*/step=20;/*步长*/fahr=lower;while(fahr<=upper){celsius=5*(fahr-32)/9;printf("%d\t%d\n",fahr,celsius);fahr=fahr+step;}fc1.c}2004-12-19ATutorialIntroduction32004-12-19ATutorialIntroduction41代码风格没有代码风格#include<stdio.h>#include<stdio.h>/*对fahr=0,20,...,300main(){intfahr,celsius;打印华氏温度与摄氏温度对照表*/intlower,upper,step;main()lower=0;upper=300;step=20;{fahr=lower;intfahr,celsius;while(fahr<=upper){intlower,upper,step;celsius=5*(fahr-32)/9;printf("%d\t%d\n",fahr,celsius);lower=0;/*温度表的下限*/fahr=fahr+step;}}upper=300;/*温度表的上限*/step=20;/*步长*/fahr=lower;http://www.ioccc.orgwhile(fahr<=upper){TheInternationalObfuscatedCCodeContestcelsius=5*(fahr-32)/9;两个获奖的例子:dance.c、sqrt.cprintf("%d\t%d\n",fahr,celsius);dance.csqrt.cfahr=fahr+step;}}fc1.cfc2.c2004-12-19ATutorialIntroduction52004-12-19ATutorialIntroduction6更简单、精确的对照表打印程序字符输入输出#include<stdio.h>„c=getchar()#defineLOWER0/*表的下限*/从键盘读入一个字符,赋值给变量#defineUPPER300/*表的上限*/–从键盘读入一个字符,赋值给变量c#defineSTEP20/*步长*/„putchar(c)/*打印华氏-摄氏温度对照表*/把c输出到屏幕main()–c{„拷贝的基本思想:intfahr;读一个字符该字符不是文件结束指示符for(fahr=LOWER;fahr<=UPPER;fahr=fahr+STEP)while()printf("%3d#%6.1f\n",输出刚读进的字符fahr,读下一个字符(5.0/9.0)*(fahr-32));}fc3.c2004-12-19ATutorialIntroduction72004-12-19ATutorialIntroduction82拷贝(Copy)一个更好的版本#include<stdio.h>#include<stdio.h>用于将输入复制到输出的程序;第个版本/*1*//*用于将输入复制到输出的程序;第2个版本*/main()main(){main()intc;{intc;c=getchar();while(c!=EOF){while(c!=EOF){while((c=getchar())!=EOF)putchar(c);c=getchar();putchar(c);}}}copy1.ccopy2.c2004-12-19ATutorialIntroduction92004-12-19ATutorialIntroduction10计算行数加法器#inclu