第四周作业

5

#include <iostream>    
    
using namespace std;    
    
int main()    
{    
    int i=0;    
    double value=1,fact=1;    
    while (fact>=10e-6)      
    {    
        i++;    
        fact=fact/i;    
        value+=fact;    
    }    
    cout << "e = "<<value<<endl;    
    return 0;    
}    


6

#include <iostream>  
using namespace std;  
  
int main()  
{  
    double pi, i, k, t;  
    pi = 0,k = i = t = 1;  
    while(t>10e-6)  
    {  
        pi += 4*1.0/i*k;  
        t = 1.0/i;  
        k *= -1;  
        i = i+2;  
          
    }  
    cout<<"pi = "<<pi<<endl;  
          
    return 0;  
}  


7

#include<iostream>  
using namespace std;  
int main()  
{  
    int a;  
    cout<<"请输入一数值:";  
    cin>>a;  
    if(a<10) cout<<a<<"is-∞to10";  
    else if(a>=10&&a<=100) cout<<a<<"is10to100";  
    else if(a>100&&a<=1000) cout<<a<<"is100to1000";  
    else cout<<a<<"is1000to+∞";  
    return 0;  
}  

8

#include<iostream>  
#include<iomanip>  
using namespace std;  
int main()  
{  
    cout<<setw(7)<<"*"<<endl;  
    cout<<setw(9)<<"* * *"<<endl;  
    cout<<setw(11)<<"* * * * *"<<endl;  
    cout<<setw(13)<<"* * * * * * *"<<endl;  
    cout<<setw(11)<<"* * * * *"<<endl;  
    cout<<setw(9)<<"* * *"<<endl;  
    cout<<setw(7)<<"*"<<endl;  
    return 0;  
}  


9

#include <iostream>    
    
using namespace std;    
    
int main()    
{    
  int sum=0,n;  
  for(n=1; ;n++)         
  {  
      sum+=n*n;  
      if(sum>=1000)        
          break;  
  }  
  sum-=n*n;  
  cout<<"满足“1^2+2^2+3^2+…+n^2<=1000”的最大n值为"<<n-1<<endl;  
    return 0;    
}    


10

#include<iostream>  
using namespace std;  
  
int main()  
{  
    long unsigned int a=0,sum1=0,sum2=0;  
    double b=0.01;  
    while(a<30)  
    {  
        sum1 +=100000;  
        b=b*2;  
        sum2 +=b;  
        a++;  
    }  
    cout<<"陌生人一共给了百万富翁"<<sum1<<"元"<<endl;  
    cout<<"百万富翁一共给了陌生人"<<sum2<<"元"<<endl;  
  
    return 0;  
}  


作业2

#include<iostream>  
using namespace std;  
  
  
int main()  
{  
    int x,y,z,sum,num;  
    for(x=0;x<=20;x++)  
        for(y=0;y<34;y++)  
            for(z=0;z<=99;z+=3)  
            {  
                sum =x+y+z;  
                num =5*x+3*y+z/3;  
                if(sum==100&&num==100)  
                {  
                cout<<"公鸡数为:"<<x<<endl;  
                cout<<"母鸡数为:"<<y<<endl;  
                cout<<"小鸡数为:"<<z<<endl;  
                cout<<"另一种情况如下:"<<endl;  
                }  
            }  
  
                return  0;  
}  


作业3

#include<iostream>  
using namespace std;  
  
int main()  
{  
    long int n,i=0,sum=0;  
    cout<<"请输入一个数:"<<endl;  
    cin>>n;  
    while(n!=0)  
    {  
    sum +=n%10;  
    n=n/10;  
    i++;  
    }         
    cout<<"所输入的数是一个"<<i<<"位数"<<endl;  
    cout<<"各位数之和是:"<<sum<<endl;      
  
        return 0;  
}  


作业4

#include <iostream>  
using namespace std;  
   
int main()  
{  
       int x, y;  
       cout<<"请输入该点的横坐标:";  
       cin>>x;  
       cout<<"请输入该点的纵坐标:";  
       cin>>y;  
       cout<<"该点的坐标为:"<<"("<<x<<","<<y<<")"<<endl;  
       if(((x+2)*(x+2)+(y+2)*(y+2)<=1)  
           ||((x-2)*(x-2)+(y+2)*(y+2)<=1)  
           ||((x+2)*(x+2)+(y-2)*(y-2)<=1)  
           ||((x-2)*(x-2)+(y-2)*(y-2)<=1))  
               cout<<"该点建筑物的高度为10m。"<<endl;  
       else  
           cout<<"该点建筑物的高度为0m。"<<endl;  
       return 0;  
}  


作业5

#include<iostream>    
using namespace std;    
int main()    
{    
int n,x,a=1,sum=0,s;    
cout<<"请输入一个数:"<<endl;  
cin>>x;  
n=1;  
s=1;  
while(n<=x)  
{  
s*=n;  
sum+=s;  
n++;  
}  
cout<<x<<"的各阶乘的和sum="<<sum<<endl;  
  
return 0;  
}  


作业6

#include <iostream>  
using namespace std;  
  
int main()  
{  
    int x1,x2,day;  
        day=1;  
        x2=1;  
        do  
        {  
            x1=(x2+1)*2;                   
            x2=x1;  
            day++;  
        }while(day<=9);  
    cout<<"苹果的总数是"<<x1<<endl;  
    return 0;  
}  


作业7

#include<iostream>  
using namespace std;  
  
int main()  
{  
    int a,b=0,n,s=0,i=1;  
    cout<<"s[n]=a+aa+aaa+aa...a(n个)的值。"<<endl;  
    cout<<"请输入一个小于10的正整数a"<<endl;  
    cin>>a;  
    cout<<"请输入一个正整数n"<<endl;  
    cin>>n;  
    while(i<=n)  
    {  
        b=b*10+a;  
        s +=b;  
        i++;  
          
    }  
    cout<<"s[n]="<<s<<endl;  
  
    return 0;  
}  


作业8

#include <iostream>    
using namespace std;    
    
int main()    
{    
    int i,j;    
    for(i=1;i<=9;i++)    
    {    
      
    for(j=1;j<=9;j++)    
    cout<<left<<"\t"<<i<<"×"<<j<<"="<<i*j;  
    cout<<endl;  
    }  
    return 0;    
}    


作业9

#include<iostream>    
using namespace std;  
  
    
int main()    
{    
    int m=0;    
    char x,y,z;   
    cout<<"将张三,李四,王五分别记为a,b,c"<<endl;    
    cout<<"将陈六,赵七,宋八分别记为A,B,C"<<endl;    
    for(x='A';x<='C';x++)    
        for(y='A';y<='C';y++)    
            for(z='A';z<='C';z++)    
            {    
                if(x!=y&&x!=z&&y!=z)    
                {    
                    if(x!='A'&&z!='A'&&z!='C')    
                    {    
                        cout<<"比赛名单如下:"<<endl;    
                        cout<<"a--"<<x<<"  "<<"b--"<<y<<"  "<<"c--"<<z<<"  ";    
    
                    }    
                }    
            }    
     return 0;    
}    





评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值