浙江大学C语言课件.ppt

浙江大学C语言课件.ppt

ID:59468760

大小:2.06 MB

页数:220页

时间:2020-09-14

浙江大学C语言课件.ppt_第1页
浙江大学C语言课件.ppt_第2页
浙江大学C语言课件.ppt_第3页
浙江大学C语言课件.ppt_第4页
浙江大学C语言课件.ppt_第5页
资源描述:

《浙江大学C语言课件.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、TheCProgrammingLanguageIntroductionCisageneral-purposeprogramminglanguageCprovidesthefundamentalcontrol-flowconstructionsCisarelatively“low-level”languageCprovidesnooperationstodealdirectlywithcompositeobjectsCoffersonlystraightforward,single-threadcontrolflowCisind

2、ependentofanyparticularmachinearchitectureSomeofCoperatorshavethewrongprecedenceSomepartsoftheCsyntaxcouldbebetterChapter1.ATutorialIntroductionLetusbeginwithaquickintroductiontoCWritingaprograminCtoprintthewords:hello,worldInC,theprogramtoprint”hello,world”is:#incl

3、udemain(){printf(“hello,world”);}It’seasy!includeinformationaboutstandardlibrarymainfunctionwithnoargumentscalllibraryfunctionnamedprintfstatementsofmainareenclosedinbraceTheprogramwouldbewritten:#includemain(){printf(“hello,“);printf(“world”);pr

4、intf(“”);}【example】Calculate1+2+3+……+100◆Howtocalculatea+b(ifa=1,b=2)main(){inta,b,sum;variablesdeclearedbeforeuseda=1;b=2;sum=0;sum=a+b;printf(“%d”,sum);}◆Howtocalculatea+b+c(ifa=1,b=2,c=3)main(){inta,b,c,sum;a=1;b=2;c=3;sum=0;sum=a+b;sum=sum+c;printf(“%d”,su

5、m);}Understand?Letmesee.【example】Calculate1+2+3+……+100◆Howtocalculate1+2+3+……+100main(){inti,sum;i=1;sum=0;while(i<=100){sum=sum+i;i=i+1;}printf(“%d”,sum);}It’seasytoo!Ifa,binputtedfromkeyboardwithdifferentvalues?◆Howtocalculatea+b(ifa,binputted)main(){inta,b,sum;

6、scanf(“%d%d”,&a,&b);sum=a+b;printf(“%d”,sum);}Ican!inputfromkeyboardEXAMPLE:编1-1/2+1/3-1/4+......,下面是编的程序,但是结果是0.000,可能是小数整数没有转换好,可是不知道哪里错了?????#include main() {  float t,i,sum,n;i=1.0;sum=0.0;t=1;n=1.0;  while(n<=100000){       t=t*(-1);       i=t/n;     

7、  sum=sum+i;       n=n+1;       };  printf("%.4f",i);  }EXAMPLE:大小字符转换:(pleaseanswer)charc;小变大:if()大变小:if()1.2VariablesandArithmeticExpressionsInC,allvariablesmustbedeclaredbeforetheyareused.Formats:typevariablesExamplesintfahr,celsius;intlower,upper,step;floattot

8、al;InC,anexpressioniscomposedwith:constantsvariablesfunctionsoperatorsExamples:fahr=fahr+step1.2VariablesandArithmeticExpressionsProgramEx

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。