第三章作业

书上第五题。

#include<iostream>
using namespace std;
int main()
{   long double temp=1.0,e=1.0;
    long double f=1;
	for(int i=1;;i++){
        f*=i;
        e+=1.0/f;
        if((e-temp)<1e-6)
			break;
		temp=e;
	}
	cout<<"e的近似值为:"<<e<<endl;
	return 0;
}


 第六题

#include<iostream>
using namespace std;
int main()
{ long double a=1.0,e=1.0;
long double f=1.0;
for(int i=3;1.0/(i-1)>=1e-6;i+=2)
{
a*=-1.0;
e+=a/(i-1);
}
cout<<"π/4的近似值为:"<<e<<endl;
return 0;
}

第七题

#include<iostream>
using namespace std;
int main()
{  int n;
cout<<"请输入一个要进行分类的数(-∞ - 1000):";
cin>>n;
if(n<10)
cout<<"这个数小于10"<<endl;
if(n>=10&&n<=100)
cout<<"这个数大于10小于100"<<endl;
if(n>100&&n<=1000)
cout<<"这个数大于100小于1000"<<endl;
if(n>1000)
cout<<"这个数大于1000"<<endl;
return 0;
}

第八题

#include<iostream>
using namespace std;
int main()
{ cout<<"      *   "<<endl;
  cout<<"    * * *  "<<endl;
  cout<<"  * * * * * "<<endl;
  cout<<"* * * * * * *"<<endl;
  cout<<"  * * * * * "<<endl;
  cout<<"    * * *  "<<endl;
  cout<<"      *   "<<endl;
  return 0;
}
 so easy!

第九题

#include<iostream>
using namespace std;
int main()
{ 
	int a=1000,i;
  for(i=0;;i++)
  {	  a-=i*i;
      if(a<=0)
		  break;
  }
  cout<<"最大的n值为:"<<i<<endl;
  return 0;
}


第十题

#include<iostream>
using namespace std;
int main()
{ 
	long a=0.01,b,c,i;
for(i=1;i<=30;i++)
{  
	a=2*a;
	b+=a;
    c=100000*30;
}
cout<<"富人给陌生人:"<<b<<"元"<<endl;
cout<<"陌生人给富人:"<<c<<"元"<<endl;
return 0;
}

99算法表
#include<iostream>
using namespace std;

void mt1();
void mt2();
void mt3();

int main(){
	mt1();
	cout<<endl;
	mt2();
	cout<<endl;
	mt3();
	return 0;
}

void mt1(){
	cout<<"九九乘法表1:"<<endl;
	for(int i=1;i<10;i++){
		for(int j=1;j<10;j++)
			cout<<j<<"*"<<i<<"="<<i*j<<'\t';
		cout<<endl;
	}
}

void mt2(){
	cout<<"九九乘法表2:"<<endl;
	for(int i=1;i<10;i++){
		for(int j=1;j<=i;j++)
			cout<<j<<"*"<<i<<"="<<i*j<<'\t';
		cout<<endl;
	}
}

void mt3(){
	cout<<"九九乘法表3:"<<endl;
	for(int i=1;i<10;i++){
		for(int j=1;j<10;j++)
			if(j<i)
				cout<<'\t';
			else
				cout<<j<<"*"<<i<<"="<<i*j<<'\t';
			cout<<endl;
	}
}

不会。照打的。



求鸡的问题

#include<iostream>
using namespace std;
int main()
{   long x,y,z; 
    for(x=0;x<=20;x++)
		for(y=0;y<33;y++)
			for(z=0;z<99;z+=3)
	if(x+y+z==100&&5*x+3*y+(1/3)*z==100)
	{	cout<<"鸡翁个数为:"<<x<<"只"<<endl;
        cout<<"鸡母个数为:"<<y<<"只"<<endl;
		cout<<"鸡雏个数为:"<<z<<"只"<<endl;
	}
	return 0;
}


整数的那个问题

#include<iostream>
using namespace std;
int main()
{   int i,a,b,c,d,f;
    cout<<"请输入一个整数:"<<endl;
    cin>>a;
	c=a;
	b=0;
	f=0;
    for(i=0;a>0;i++)     
    { 
		a/=10;
		b++;
	}
	cout<<"它有"<<b<<"个数"<<endl;
    for(d=0;d<b;d++)
	{   
	    f+=c%10;
        c=c/10;
	}
	cout<<"它各个位数上的和为:"<<f<<endl;
return 0;

}


4.在一个平面上,有四个圆柱形塔,塔底圆心坐标分别为(2,2)、(-2,2)、(-2,-2)、(2,-2),塔半径为1,塔高为10米,塔外无建筑物。编程,输入任一个点平面坐标,求该点建筑物的高度。

   完全读不懂题目的意思。这东西是三维的? 用二维的点坐标去求高度??   


 求阶乘

#include<iostream>
using namespace std;
int main()
{   int s,i,n,k; 
    s=0;
	k=1;
	cout<<"求s=1!+2!+3!++···++n!,请输入那个n"<<endl;
	cin>>n;
	for(i=1;i<=n;i++)
	{   k*=i;
		s+=k;
	}
	cout<<"s=1!+2!+3!++···++n!="<<s<<endl;
return 0;
}
	  
	  

猴子吃苹果

#include<iostream>
using namespace std;
int main()
{   int n,i;
    n=1;
    for(i=10;i>0;i--)
	{	n=2*n+1;}
	cout<<"一开始有"<<n<<"个苹果"<<endl;
	return 0;          /***********屎上最能吃的猴子************/
}

。。 后面几道题理解力、还有个人能力不足,想破脑袋都想不出来。


  错误总结  1.  常常有变量的值,像SUM值之类的没先定义就用了,导致程序老是出错。

                    2.for(:::)内的三个:所代表的意思不同,出了不少错。

                      +++++++++++++...............。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值