第4周作业

习题5

#include <iostream>
using namespace std;

int main()
{
	int i=1,sum=1;
	long double e=1.0;
	for( i=1;1.0/sum>=1e-6;i++)
	{
		sum=sum*i;
		e=e+1.0/sum;
	}
	cout<<"自然对数 e 的近似值为:"<<e<<endl;
	return 0;
}


习题6

#include<iostream>

using namespace std;
int main()
{
    int i;
	double sum=0, j;
	for(i=1;j>=1e-6;i++)
	{
		j=1/(2*i-1);
		if(i/2==i/2.0)
			sum-=j;
		else
			sum+=j;
	}
	cout<<"π="<<sum*4<<endl;
	return 0;
}

习题7

#include <iostream>
using namespace std;

int main()
{
	int t;
	cout<<"请输入一个整数:"<<endl;
	cin>>t;
	if(t<10)
		cout<<t<<"is less than 10.";
	else if(t<=99)
		cout<<t<<"is 10 to 99.";
	else if(t<=999)
		cout<<t<<"is 100 to 999.";
	else
		cout<<t<<"is more than 1000.";
	cout<<endl;
	return 0;
}


习题8.。。。。。不会高级的方法

#include<iostream>
using namespace std;
int main()
{
	    cout<<"      *\endl"
		<<"    * * *\endl"
		<<"  * * * * *\endl"
		<<"* * * * * * *\endl"
		<<"  * * * * *\endl"
		<<"    * * *\endl"
		<<"      *\endl";

return 0;
}


习题9

#include<iostream>
using namespace std;
int main()
{
	
	int n=0,s=0;
	while(s<=1000)
	{
		n++;
		s+=n*n;
	}
	cout<<"满足条件的最大值";
	cout<<"n="<<n-1<<endl;
     return 0;
}

百钱百鸡

#include<iostream>
using namespace std;	

int main()
{
	int a,b,c; 
	int i=0; 
	cout<<"鸡翁一值钱五,\n鸡母一值钱三,\n鸡雏三值钱一。\n百钱买百鸡,\n问鸡翁、鸡母、鸡雏各几何?\n\n";	   
	for(a=0;a<=20;a++)	
		for(b=0;b<=33;b++)		
			for(c=0;c<=100;c+=3)
			{	
				if(5*a+3*b+c/3==100 && a+b+c==100)		
				{	
					i++;
					cout<<"\n第"<<i<<"种方案\n\n";	 
					cout<<"..............................\n";
					cout<<" 公鸡的只数 :"<<a<<"只\n"<<" 母鸡的只数 :"<<b<<"只\n"<<" 小鸡的只数 :"<<c<<"只\n";
				}
			}
			
			return 0;
			
			
}


乘法表


#include<iostream>
#include<windows.h>
using namespace std;
int main()
{
	int i,j=0;
	for(i=0;i<=9;i++)
		for(j=1;j<=i;j++)
		{
			Sleep(300);
			cout<<j<<'*'<<i<<'='<<i*j<<"  \a"; 
			if(j==i)	
				cout<<"\n\n"<<' ';
		}
		return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值