第四周作业

一:

5.求自然对数e的近似值

// 223.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

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


 

6.求圆周率的近似值

// 223.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
{
	long double pi=1.0;
	double flag =-1.0;
	for(int i=3;1.0/i>=1e-6;i+=2)
	{
		pi+=flag/i;
		flag=-flag;
	}
	cout<<"圆周率pi的近似值为:"<<4*pi<<endl;

	return 0;
}

 

7,编一程序,,,分类并显示

// 223.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

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



8.编一程序,输出图形

#include <iostream>
using namespace std;

int main()
{
	int i,j,k;
	for(i=0;i<=3;i++)
	{
		for(j=0;j<6-2*i;j++)
			cout<<" ";
		for(k=0;k<2*i+1;k++)
			cout<<" *";
		cout<<endl;
	}

	for(i=0;i<=2;i++)
	{
		for(j=0;j<2+2*i;j++)
			cout<<" ";
		for(k=0;k<5-2*i;k++)
			cout<<" *";
		cout<<endl;
	}
	return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值