您的位置:首页 > 其它

第四周作业

2014-04-01 01:25 134 查看
 实验作业
1.完成课本每一个编程题。要求先画出流程算法图或N-S图,然后编程实现,有可能的话使用两种以上方法;
2.编程求“百钱百鸡”问题。(鸡翁一值钱五,鸡母 一值钱三,鸡雏三值钱一。百钱买百鸡,问鸡翁、鸡母、鸡雏各几何?)
3.编程输入一个整数,计算它是几位数字,分别输出每一位数字,并输出各个数位上数字之和。
4.在一个平面上,有四个圆柱形塔,塔底圆心坐标分别为(2,2)、(-2,2)、(-2,-2)、(2,-2),塔半径为1,塔高为10米,塔外无建筑物。编程,输入任一个点平面坐标,求该点建筑物的高度。
5.编程计算s=1!+2!+3!+......n!(其中n为整数,n!表示计算n阶乘),要求使用两种以上的方法。
6.猴子吃苹果问题:猴子第一天摘了若干个苹果,当时吃了一半,还不过隐,又多吃了一个。第二天,又吃掉余下的一半,又多吃一个。以后每一天,都是吃掉前一天余下的一半零一个。到第10天,只有一个苹果了。问猴子第一天共摘了多少个苹果?
7.计算s
=a+aa+aaa+aa...a(n个)的值。其中a是一个数字,n表示a的位数。例如,当a=1,n=5时,则要计算的表达式为
    s[5]=1+11+111+1111+11111
8.打印九九乘法表。
9.两个羽毛队进行单打比赛,各出3个人。甲队为张三、李四、王五3个队员,已队为陈六、赵七、宋八3个队员。现已经抽签决定比赛名单,有人向队员打听比赛名单,张三说他不和陈六打,王五说他不和陈六和宋八打。请编程找出3对比赛名单。
10.积累调试程序经验,收集错误信息原因(每个同学收集3-5条错误信息原因,并输入电脑形成文字)。
n      作业要求
网上提交各个程序和相关要求的文字。
可以分两个博客文章来交。前5个题和后5个题各放到一个博客文章中提交。
程序1

#include "stdafx.h"  
#include<iostream>
#include<iomanip>  
using namespace std;  
int main()
{
  double e=1,t=1;  
  int n, i,f=1;  
  for(i=1;;i++)  
  {  
    f*=i; 
    e+=1.0/f;  
  if(1.0/f<1e-6)  
      break;  
  
  }  
  cout<<"自然对数e的近似值为:"<<setprecision (8)<<e<<endl;  

return 0;
}




程序2

#include "stdafx.h"
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{   int a,b=0;
double c=0,pi;
for(a=1;1.0/a>=1e-8;a+=2)
{
c+=pow(-1,b)*(1.0/a);
b++;
}
pi=4*c;
cout<<"圆周率PI的值约为:"<<pi<<endl;
return 0;
}




程序3

#include "stdafx.h"
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{   float a,b;
int c,d=0;
cout<<"please input a number"<<endl;
cin>>a;
for(b=10;b<a;b*=10)
{
if(a/b>1)
c=1;
d+=c;
}
switch(d)
{
case 0:cout<<a<<"is 0 to 10"<<endl;break;
case 1:cout<<a<<"is 10 to 100"<<endl;break;
case 2:cout<<a<<"is 100 to 1000"<<endl;break;
default:
cout<<a<<"is larger than 1000"<<endl;
}
return 0;
}


程序4

#include "stdafx.h"
#include<iostream>
#include<iomanip>
#include<cmath>
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;
}




程序5

#include "stdafx.h"
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{   int a,b,c;
for(a=1;a<=9;a++)
{
for(b=1;b<=a;b++)
{
c=b*a;
cout<<b<<"x"<<a<<"="<<c<<"\t";
}
cout<<endl; }

return 0;
}




程序6

#include "stdafx.h"
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{   int a,b,c;
for(a=0;a*5<=100;a++)
for(b=0;(a*5+b*3)<=100;b++)
{
c=100-a-b;      //百鸡
if((a*5+b*3+c/3==100)&&(c%3==0))    //百钱
cout<<"公鸡有"<<a<<"只"
<<"母鸡有"<<b<<"只"
<<"小鸡有"<<c<<"只"<<endl;
}

return 0;
}




程序7

#include "stdafx.h"
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{   long int a,i;
int k=0,h,m=0;
cout<<"输入一个整型数:";
cin>>a;
for(i=10;i<=100000000;i=i*10)
{
k++;
if(a<i)
break;
}
cout<<"位数:";
cout<<k<<endl;
cout<<"输出各位数值:";
while(i>1)
{
i=i/10;
h=a/i;
a=a%i;
m+=h;
cout<<h<<' ';

}
cout<<endl;
cout<<"各个位的数值和:"<<m<<endl;

return 0;
}


程序8

#include "stdafx.h"
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{  float x,y;
cout<<"请输入点坐标,坐标值用空格键隔开"<<endl;
cin>>x>>y;
if(x<0)
x=-x;
if(y<0)
y=-y;
if((x-2)*(x-2)+(y-2)*(y-2)<=1)
cout<<"该点建筑高度为10米"<<endl;
else
cout<<"该点建筑高度为0米"<<endl;
return 0;
}


程序9

#include "stdafx.h"
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main()

{
int a,b,c,d,s=0;
cout<<"你想计算到第几项?"<<endl;
cin>>c;
for(a=c;a>0;a--)
{
d=1;
for(b=a;b>=1;b--)
d*=b;
s+=d;
}
cout<<"级数前"<<c<<"项之和为:"<<s<<endl;
return 0;
}


程序10

#include "stdafx.h"
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main()

{
int a=10,b=1,c=0;
for(a;a>1;a--)
{
c=2*(b+1);
b=c;
}
cout<<"猴子第一天共摘了"<<c<<"个苹果"<<endl;
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: