第四周

#include<iostream>  
using namespace std;  
int fac(int n)  
{   int result = 1;  
    while (n>0)  
    {   result *= n;  
        n--;  
    }  
    return result;  
}  
int main()  
{  
    int n=1;  
    double e=0,t=1;  
    for(;t>=1e-6;n++)  
    {  
        e+=t;  
        t=1.0/fac(n);  
  
      
    }  
    cout<<"e="<<e<<endl;  
      
    return 0;  
}  
#include<iostream>  
#include<cmath>  
using namespace std;  
int main()  
{  
    double count=0,m=3,t=-1,z=1;  
    for(;fabs(z)>=1e-6;t=-t)  
    {  
          
        count+=z;  
        z=(1.0/m)*t;  
        m+=2;  
  
      
    }  
    cout<<"π="<<count*4<<endl;  
  
  return 0;  
}  
#include <iostream>  
using namespace std;  
int main()  
{  
  int n;  
  cout<<"please enter a number"<<endl;  
  cin>>n;  
  if((n/10)==0)  
      cout<<n<<" is less than 10"<<endl;  
  else if((n/100)==0)  
      cout<<n<<" is 10 to 100"<<endl;  
  else if((n/1000)==0)  
      cout<<n<<" is 100 to 1000"<<endl;  
  else  
      cout<<n<<" is more than 1000"<<endl;  
  
  return 0;  
}  

#include<iostream>  
#include<iomanip>  
using namespace std;  
int main()  
{  
    int j,i;  
    for(i=1; i<=4; i++)  
    {  
        for(j=1; j<=5-i; j++)  
            cout<<setw(2)<<" ";    
        for(j=1;j<=2*i-1;j++)  
            cout<<setw(2)<<'*';  
     cout<<endl;  
     }  
    for(i=1;i<=3;i++)  
    {  
        for(j=4;j>=4-i;j--)  
            cout<<setw(2)<<" ";  
        for(j=4;j>=2*i-2;j--)  
            cout<<setw(2)<<'*';  
        cout<<endl;  
    }  
return 0;  
}  

#include <iostream>  
using namespace std;  
int main()  
{  
    int count=0,n=1;  
    for(;count<=1000;n++)  
    {  
        count+=n*n;  
  
      
    }  
    cout<<"n="<<n-1<<endl;  
  
  
  return 0;  
}  

#include<iostream>  
#include<cmath>  
using namespace std;  
int main()  
{  
    double sum1=0,sum2=0.1,day=1;  
    for(;day<=30;day++)  
    {  
        sum1+=100000;  
        sum2*=2;  
      
    }  
    cout<<"陌生人给了百万富翁:"<<std::fixed<<sum1<<"元"<<endl;  
    cout<<"百万富翁给了陌生人:"<<std::fixed<<sum2<<"元"<<endl;  
  
  return 0;  
}  

#include <iostream>  
using namespace std;  
int main()  
{  
  int i=1;  
  int t=1;  
  while(i<=9)  
  {  
      
    while(t<=i)  
    {  
      cout<<t<<"*"<<i<<"="<<i*t<<" ";  
      t++;  
    }  
    t=1;  
    cout<<endl;  
    i++;  
 }  
  return 0;  
}  

#include<iostream>  
using namespace std;  
int main()  
{  
    int i=0;  
    int x,y,z;  
    double money;  
    for(x=0;x<=20;x++)  
    {  
        for(y=0;y<34;y++)  
        {  
            z=100-x-y;  
            money=5*x+3*y+z/3.0;  
          
            if(money==100)  
            {  
                i++;  
                cout<<endl;  
                cout<<"第"<<i<<"种情况"<<endl;  
                cout<<"鸡翁的数量x="<<x<<endl;  
                cout<<"鸡母的数量y="<<y<<endl;  
                cout<<"鸡雏的数量z="<<z<<endl;  
              
            }  
        }  
    }  
    return 0;  
}  

#include<iostream>  
#include<iomanip>  
using namespace std;  
int main()  
{  
    int n,count=0,i,m=0;  
    cout<<"please enter a number:"<<endl;  
    cin>>n;  
    while(n!=0)  
    {  
        i=n%10,m+=i,cout<<setw(8)<<i;  
        n=n/10,count++;  
  
      
    }  
    cout<<"        位数:"<<count<<"    各数位和:"<<m<<endl;  
    cout<<"由左往右依次为个位、十位、百位---"<<endl;  
  
      
    return 0;  
  
}  

#include<iostream>  
#include<cmath>  
using namespace std;  
int main ()  
{  
    double x,y,x1,x2,x3,x4;  
    cout<<"请输入点的坐标x y"<<endl;  
    cin>>x>>y;  
    x1=sqrt(pow(x-2,2)+pow(y-2,2));  
    x2=sqrt(pow(x-2,2)+pow(y+2,2));  
    x3=sqrt(pow(x+2,2)+pow(y-2,2));  
    x4=sqrt(pow(x+2,2)+pow(y+2,2));  
    if(x1<=1||x2<=1||x3<=1||x4<=1)  
        cout<<"该点高度为10"<<endl;  
    else  
        cout<<"该点高度为0"<<endl;  
    return 0;  
  
}  

#include<iostream>  
using namespace std;  
int fac(int n)  
{   int result = 1;  
    if(n<0)  return -1;  
    else    if(n == 0)  return 1;  
    while (n>0)  
    {   result *= n;  
        n--;  
    }  
    return result;  
}  
int main()  
{  
    int count=0,n;  
    cout<<"请输入阶数:"<<endl;  
    cin>>n;  
    if(n==0||n==1)  
        cout<<"result=1"<<endl;  
    else  
    {  
        for(;n>=1;n--)  
            count+=fac(n);  
        cout<<"result="<<count<<endl;  
    }  
      
    return 0;  
}  

#include<iostream>  
using namespace std;  
int main()  
{  
    int day=1,n=1;  
    for(;day<=9;day++)  
    {  
        n=2*(n+1);  
      
      
    }  
    cout<<"苹果数为:"<<n<<endl;  
    return 0 ;  
  
}  

#include<iostream>  
#include<cmath>  
using namespace std;  
int fac(double x,double y)  
{  
    y=y-1;  
    double result=0;  
    for(;y>=0;y--)  
    {  
        result+=x*pow(10,y);  
    }  
    return result;  
      
}  
int main()  
{  
    double sum=0;  
    int a,n,m;  
    cout<<"请输入数字a和位数n"<<endl;  
    cin>>a>>n;  
    m=n;  
    for(;n>=0;n--)  
    {  
        sum+=fac(a,n);  
    }  
    cout<<"s["<<m<<"]="<<sum<<endl;  
    return 0;  
  
}  



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值