章5
来源:互联网 发布:统计软件spss 编辑:程序博客网 时间:2024/05/04 21:05
#include<iostream>using namespace std;int ncomp(int i,int j){if (i>j) return 1;if (i==j) return 0;return -1;}int main(){int k=2;int n=ncomp(k,++k); //从右到左顺序,先求++k,此后k=3cout<<n<<endl;return 0;}
#include<iostream>using namespace std;void swap(int u,int v){int temp; //此处temp为中介值而非终值无需返回temp=u;u=v;v=temp;}int main() //值调用发不能实现互换,因为值调用法被调用函数形参不能影响主函数实参的值!!{int a=3,b=4;cout<<a<<"\t\t"<<b<<endl;cout<<a<<"\t\t";swap(a,b);cout<<b<<endl;return 0;}
#include<iostream>using namespace std;void swap(int &u,int &v) //引用调用{int temp; //此处temp为中介值而非终值无需返回temp=u;u=v;v=temp;}int main() {int a=3,b=4;cout<<a<<"\t\t"<<b<<endl;swap(a,b);cout<<a<<"\t\t"<<b<<endl;return 0;}
#include<iostream>using namespace std;long f2(int);long f1(int p){int k;long r;k=p*p;r=f2(k);return r;}long f2(int q){long fact=1;for(int i=1;i<=q;i++)fact*=i;return fact;}int main(){int i;long sum=0;for(i=2;i<4;i++)sum+=f1(i);cout<<sum<<endl;return 0;}
#include<iostream>#include<iomanip>using namespace std;float f(float x);float root(float x1,float x2);float point(float x1,float x2);int main(){float x1,x2,y1,y2,x;d0{cout<<"请输入根所在范围:";cin>>x1>>x2;y1=f(x1);y2=f(x2);cout<<"两端点的值为:["<<y1<<","<<y2<<"']"<<endl;}while(y1*y2>=0);x=root(x1,x2);cou<<"x="<<x<<endl;return 0;}float f(float x){return(x*x*x-4*x*x+6*x-10);}float root(float x1,x2);{float y,x,y1;y1=f(x1);do{x=point(x1,x2);y=f(x);if(y*y1>0){y1=y;x1=x;}else x2=x;}while (fabs(y)>=0.0001);retyrn x;}float point(float x1,float x2){float y;y=(x1*f(x2)-x2*f(x1)/(f(x2)-f(x1));retirn y;}return 0;}
0 0
- 章5
- 第5章习题5
- 第5章 继承
- 第5章 函数
- 第5章、异常
- 第5章 常量
- 5章 程序设计基本概念
- 第5章 表达式
- 第5章 继承
- 5-7章
- 第5章 函数
- 第5章 配置
- 汇编--5章习题
- 第5章 高深莫测
- 第5章---多态性
- 第5章 表达式
- 第5章 STL
- 第5章、按钮
- 黑马程序员_多线程
- 数据结构-树
- phpcms v9 模板标签说明大全
- CSDN开源夏令营学生报名已经开始,你准备好了吗?
- jquery对象怎么转换为html对象(也就是js的dom对象)
- 章5
- Git的相关应用配置详解
- Android实现计时与倒计时的几种方法
- ARM-LINUX交叉编译环境的搭建
- Gerrit FAQ
- 包管理器Bower使用手册之一
- 十进制转二进制、十进制转十六进制
- html滚动轮播实现
- ORA-12012 ORA-29280 ORA-06512