- 1
- 0
- 约2.82万字
- 约 116页
- 2026-03-01 发布于宁夏
- 举报
编程理念讲解
ProgrammingConcept
-2程序随便写随便对? 平方根–简单算法九九乘法表forLoopvs.whileLoopPascalTriangle二进制也可以很有趣--如何印出该六张卡片?
-3印出根号2/*写个程序印出根号2*/#includestdio.hdoublesqrt(double);//#includemath.hintmain(){printf(sqrt根号2=%f\n,sqrt(2.0));//C++式的注解commentprintf(Byebye!\n);return0;}sqrt是程序库里的一个函数(function,函式)C型式的注解C++型式的注解
-4印出根号3/*写个程序印出根号3*/#includestdio.hdoublesqrt(double);//#includemath.hintmain(){printf(sqrt根号3=%f\n,sqrt(3.0));//C++式的注解commentprintf(Byebye!\n);return0;}每次要重改程序吗?
-5印出根号x/*写个程序印出根号x*/#includestdio.h#includemath.hdoubley;intmain(){printf(Givemex:);scanf(%lf,y);printf(Sqrt(%f)=%f\n,y,sqrt(y));return0;}使用变量y传address
-6程序随便写求x的平方根蔡文能tsaiwn@csie.nctu.edu.tw交通大学信息工程学系file:///c:\course\cs2\file:///c:\course\cs2\p3.c练习使用whileloop
-7p3.c–练习whileloop#includestdio.h#includemath.hintmain()/*Thisprogramcanfindsquarerootofanynumberthat=0andwillstopwhenyouenteravaluethat0阿版权是蔡文能的,欢迎拷贝分享初学者!*/{floatonevar;/*变量名称随便我取的啦*/doubleans;/*用来放答案*/printf(FindsquarerootofX.Negativevaluewillceasetheprogram\n);printf(X=?);/*还是问X=?比较简洁有力,不用说onevar*/scanf(%f,onevar);while(onevar=0){/*只要onevar大于或等于零我们就一直重复做{...}*/ans=sqrt(onevar);/*其实sqrt的参数也应该为double型别*/printf(SQRT(%f)=%f\n,onevar,ans);printf(X=?);scanf(%f,onevar);}/*while(onevar*/return0;}
-8程序随便写求x的平方根自己如何写求SQRT?file:///c:\course\cs2\p4.cfile:///c:\course\cs2\p5.c自己如何写求SQRT?目的:练习想Algorithm长除法求平方根?适合手动做的方法不一定适合计算机做!
-9p4.c–练习想Algorithm(1/2)/*Thisprogramcanfindsquarerootofanynumberthat=0andwillstopwhenyouenteravaluethat0*//*Thisversionistryingtoshowyouthatwecanwriteourfunction/proceduretosolvetheproblem,thoughthemysqrt()isactuallycallingthesystemstandardfunction.We
原创力文档

文档评论(0)