第一次作业

2.28  
1


#include<iostream>
using namespace std;
int main()
{
    char a;

    while(true)
    {
        
        cout<<"Menu:A(dd)D(elete)S(ort)Q(uit),Select one:";
        cin>>a;
        
        if(a=='A')
        {
            cout<<"数据已经增加"<<endl;
        }
        else if(a=='D')
        {
            cout<<"数据已经删除"<<endl;
        }
        else if(a=='S')
        {
            cout<<"数据已经排序"<<endl;
        }
        else if(a=='Q')
        {
            break;
        }
    }
    return 0;
}

2

#include<iostream>
using namespace std;
int main()
{
    char a;

    while(true)
    {
        
        cout<<"Menu:A(dd)D(elete)S(ort)Q(uit),Select one:";
        cin>>a;
        switch(a)
        {

            case'A':cout<<"数据已经增加"<<endl;
                    break;

            case'D':cout<<"数据已经删除"<<endl;
                    break;

            case'S':cout<<"数据已经排序"<<endl;
                    break;

            case'Q':break;
        }
        if(a=='Q')
        break;
        
    }
    return 0;
}




2.29

1



#include<iostream>
using namespace std;
int main()
{
    int a=2,b=1;
    cout<<a<<"  ";
    while(a<=100)
    {
        int i;
        for(i=2;i<a;i++)
        {
            if(a%i==0)
            {
                break;
            }
            else if(a%i!=0&&i==a-1)
            {
                if(b%5==0)
                {
                    cout<<endl;
                }
                cout<<a<<"  ";
                b++;
            }
        }
        a++;
    }
    
    return 0;
}




2



#include<iostream>
using namespace std;
int main()
{
    int a=2,b=1;
    cout<<a<<"  ";
    do
    {
        int i;
        for(i=2;i<a;i++)
        {
            if(a%i==0)
            {
                break;
            }
            else if(a%i!=0&&i==a-1)
            {
                if(b%5==0)
                {
                    cout<<endl;
                }
                cout<<a<<"  ";
                b++;
            }
        }
        a++;
    }while(a<=100);
    
    return 0;
}


3


#include<iostream>
using namespace std;
int main()
{
    int a=2,b=1;
    cout<<a<<"  ";
    for(;a<=100;a++)
    {
        int i;
        for(i=2;i<a;i++)
        {
            if(a%i==0)
            {
                break;
            }
            else if(a%i!=0&&i==a-1)
            {
                if(b%5==0)
                {
                    cout<<endl;
                }
                cout<<a<<"  ";
                b++;
            }
        }

    }
    
    return 0;
}

2-32   1


#include<iostream>
#include<stdlib.h>
#include<ctime>
using namespace std;
int main()
{
                srand(int(time(0)));
    int a=rand()%101;
    int b=0;
    while(true)
    {
        cout<<"猜一猜数是几 "<<endl;
        cin>>b;
        if(a>b)
        {
            cout<<"小了"<<endl;
            continue;
        }
        else if(a<b)
        {
            cout<<"大了"<<endl;
            continue;
        }
        else
        {
            cout<<"恭喜你答对了"<<endl;
            break;
        }
    }
    
    return 0;
}


2


#include<iostream>
#include<stdlib.h>
#include<ctime>
using namespace std;
int main()
{
    srand(int(time(0)));
    int a=rand()%101;
    int b=0;
    do
    {
        cout<<"猜一猜数是几 "<<endl;
        cin>>b;
        if(a>b)
        {
            cout<<"小了"<<endl;
            continue;
        }
        else if(a<b)
        {
            cout<<"大了"<<endl;
            continue;
        }
        else
        {
            cout<<"恭喜你答对了"<<endl;
            break;
        }
    }while(true);
    
    return 0;
}


3




#include<iostream>
#include<stdlib.h>
#include<ctime>
using namespace std;
int main()
{
    srand(int(time(0)));
    int a=rand()%101;
    int b=0;
    for(;;)
    {
        cout<<"猜一猜数是几 "<<endl;
        cin>>b;
        if(a>b)
        {
            cout<<"小了"<<endl;
            continue;
        }
        else if(a<b)
        {
            cout<<"大了"<<endl;
            continue;
        }
        else
        {
            cout<<"恭喜你答对了"<<endl;
            break;
        }
    }
    return 0;
}




2-34  1


#include<iostream>
using namespace std;
int main()
{
    int a,b,c=1,d=1,i;
    cin>>a>>b;
    for(i=a;i>a-b;i--)
    {
        c=c*i;
    }
    for(i=1;i<=b;i++)
    {
        d=d*i;
    }
    cout<<c/d<<endl;
    return 0;
}




2

#include<iostream>
using namespace std;
int main()
{
    int a=1,b=2,c=3,d=4,e=5;
    int i,j,k,z=0;
    for(i=5;i>0;i--)
    {
        for(j=5;j>0;j--)
        {
            if(j==i)
                continue;
            for(k=5;k>0;k--)
            {
                if(k==j||k==i)
                    continue;
                switch(i)
                {
                case 1:cout<<"red"<<" ";break;
                case 2:cout<<"yellow"<<" ";break;
                case 3:cout<<"blue"<<" ";break;
                case 4:cout<<"white"<<" ";break;
                case 5:cout<<"black"<<" ";break;
                }
                switch(j)
                {
                case 1:cout<<"red"<<" ";break;
                case 2:cout<<"yellow"<<" ";break;
                case 3:cout<<"blue"<<" ";break;
                case 4:cout<<"white"<<" ";break;
                case 5:cout<<"black"<<" ";break;
                }
                switch(k)
                {
                case 1:cout<<"red"<<endl;break;
                case 2:cout<<"yellow"<<endl;break;
                case 3:cout<<"blue"<<endl;break;
                case 4:cout<<"white"<<endl;break;
                case 5:cout<<"black"<<endl;break;
                }
                z++;
            }
        }
    }
    cout<<z<<endl;
    return 0;
}

 

posted on 2019-03-17 22:19  吵闹机器人  阅读(148)  评论(2编辑  收藏  举报