补回第五章的例题部分
来源:互联网 发布:畅捷通软件不好用 编辑:程序博客网 时间:2024/06/02 16:32
例题3
01.#include<iostream> 02.using namespace std; 03.double p(double); 04. int main() 05.{ 06. double s = p(5.0); 07. cout<<"面积为"<<s<<endl; 08. return 0; 09.} 10. double p(double r) 11.{ 12. double pi =3.14; 13. double s =pi *r*r; 14. return s; } 15.4 16.#include<iostream> 17.using namespace std; 18. int sum(int x,int y) 19.{ 20. int t;t=x+y; 21. return t;} 22. int main() 23. { 24. int a,b,c; 25. a=15,b=20; 26. c=sum(a,b); 27. cout<<a<<"+"<<b<<"="<<c<<endl; 28. return 0; 29. }
例题4
01.#include<iostream> 02.using namespace std; 03. int sum(int x,int y) 04.{ 05. int t;t=x+y; 06. return t;} 07. int main() 08. { 09. int a,b,c; 10. a=15,b=20; 11. c=sum(a,b); 12. cout<<a<<"+"<<b<<"="<<c<<endl; 13. return 0; 14. }
例题7
01.#include<iostream> 02.using namespace std; 03. 04.int p(int x) 05.{ x=x*x; 06.return x;} 07.int main() 08.{int t=10;int s=p(t); 09.cout<<"t="<<t<<'\t'<<"p("<<t<<")="<<s<<endl; 10. 11. return 0; 12.}
例题13
01.#include<iostream> 02.using namespace std; 03. 04.long f2(int); 05.long f1(int p) 06.{ 07. int k; 08. long r; 09. k=p*p; 10. r= f2(k); 11. return r; 12.} 13. long f2(int q) 14.{ 15. long fact = 1; 16. for(int i =1;i<=q;i++) 17. fact *= i; 18. return fact; 19.} 20. int main() 21.{ 22. int i; 23. long sum =0; 24. for(i =2; i<=3;i++) 25. sum += f1(i); 26. cout<<"sum = "<<sum<<endl; 27. return 0; 28.}
例题15
01.#include<iostream> 02.using namespace std; 03. 04.float F(int n); 05. int main() 06.{ 07. int a; 08. float p; 09. cout<<"input an integer number:"; 10. cin>>a; 11. p =F(a); 12. cout<<a<<"! ="<<p<<endl; 13. return 0; 14.} 15. float F(int n) 16.{ 17. float fact; 18. if(n == 0) 19. fact = 1; 20. else 21. fact = n * F(n-1); 22. return fact; 23. }
例题20
01.#include<iostream> 02.using namespace std; 03. 04. 05.void sort(int); 06.void echoa(); 07. 08. 09.nt a[5] ={6,3,9,8,2}; 10. int main() 11.{ 12. echoa(); 13. sort(5); 14. echoa(); 15. return 0; 16.} 17. 18.void echoa() 19.{ 20. for(int i =0;i<5;i++) 21. cout<<a[i]<<'\t'; 22. cout<<endl; 23.} 24. void sort(int n) 25.{ 26. int i,j,min,temp; 27. for(i =0;i<n-1;i++) 28. { 29. min =i; 30. for(j=i+1;j<n;j++) 31. if(a[j]<a[min]) 32. min = j; 33. temp = a[i];a[i]=a[min];a[min]=temp; 34. } }
例题23
01.#include<iostream> 02.using namespace std; 03. 04. int f(int); 05. int main() 06. { 07. int i,k; 08. cout<<"输入一个非负整数:"; 09. cin>>k; 10. for(i=1;i<=k;i++) 11. cout<<i<<"!="<<f(i)<<endl; 12. return 0;} 13. int f(int n) 14. { 15. static int f=1;f=f*n; 16. return f; 17. }
0 0
- 补回第五章的例题部分
- 第五章 数组例题
- 《Java程序设计》第五章-例题
- [学习笔记—Objective-C]《Objective-C 程序设计 第6版》第五章 循环结构 部分例题&课后题讲解
- C++第五章例题(第七周)
- 算法入门竞赛 第五章例题 题解
- 第五章作业第一部分
- 第五章作业第二部分
- 我的C++第四周作业1(第三章部分例题与练习题)
- 紫书 p120 第五章例题5-7 丑数
- 算法竞赛第五章例题分析(Python实现):
- 第六章的例题
- 刷紫书第五章例题(例题5-1到5-7)
- java程序设计基础_陈国君版第五版_第五章例题
- 第五周作业的抄写部分
- 第五部分 Hibernate的事务和并发
- 使用java理解程序逻辑第五章(补)
- c++作业第六章例题部分(第九周)
- 计算机网络笔记---网络层---ARP(RARP省略)
- 闲情赋片段——陶渊明
- wtl : 编译问题
- ntpdate us.pool.ntp.org
- oc下实现局域网udp广播通讯使用开源框架GCDAsyncUdpSocket
- 补回第五章的例题部分
- GPS数值与距离的转换
- JAVA_OPTS remote debug
- 在软件开发生命周期中使用应用程序验证器
- 机构相关
- 计算机网络笔记---网络层---ICMP
- [Java 12 IO] OutputStream 字节输出流,继承自它的类,都是 程序中输出 数据
- 外键 外键表、主键表 数据库
- JAVA判断浏览器类型-基本操作