章5

#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=3
	cout<<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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值