第三章作业(改)

例5

#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
	cout<<"求自然对数E的值"<<endl;
	double e=0,e0=0;
	double n=0,a=1,b;
	while(n<100)
	{
		for(b=1;b<=n;b++)
		{
			a*=b;
		}
		e0=1/a;
		e+=e0;
		a=1;
		n++;
	}
	cout<<"e的近似值为:"<<setprecision(8)<<e<<endl;
	return 0;
}





题6

#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
	long int i;
	float j;
	double k=0;
	for(i=1;i<=5e7;i++)
	{
		j=1.0/(2*i-1);
		if(i/2==i/2.0)
			k-=j;
		else
			k+=j;
	}
cout<<"pai="<<setprecision(8)<<k*4<<endl;
return 0;
}


题7
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
	int i=0;
	long int a;
	float N,m;
	while(1)
	{
		cout<<"请输入一个值:"<<endl;
		cin>>N;
		for(a=1;a<=N;a=10*a)
		{
			i++;
		}
		switch(i)
		{
		case 2:
			cout<<N<<"is 10 to 100."<<endl;
			break;
		case 3:
				cout<<N<<"is 100 to 1000."<<endl;
				break;
		default:
			if(i<2)
				cout<<N<<"小于10"<<endl;
			if(i>3)
				cout<<N<<"在1000以上。"<<endl;
			break;
		}
		i=0;
	}
	return 0;
}



 

#include<iostream>
using namespace std;
int main()
{
	int i,j,k;
	for(i=7;i>=1;i-=2)
	{
		for(k=i;k>0;k--)
			cout<<' ';
		for(j=8-i;j>0;j--)
		{
			cout<<"*";
		}
		cout<<endl;
	}
	for(i=5;i>=1;i-=2)
		{
			for(k=8-i;k>0;k--)
				cout<<' ';
			for(j=i;j>0;j--)
			{
				cout<<"*";
			}
			cout<<endl;
		}
		return 0;
}


评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值