cpp实验二

##2-28

 

```c

#include<iostream>
using namespace std;
int main()
{
char a;
while (true)
{
cout<< "Menu:A(dd) D(elete) S(ort) Q(uit)"<<endl<<"Select one:";
cin>>a;
switch (a)
{
case 'A':cout<<"数据已经增加"<<endl;continue;
case 'D':cout<<"数据已经删除"<<endl;continue;
case 'S':cout<<"数据已经排序"<<endl;continue;
case 'Q':break;
default:cout<<"输入错误!";continue;
}
break;
};

return 0;
}


```

##2-29

```c

#include<iostream>using namespace std;

int main()
{
int b=2,flag=1,a=2;
do
{
flag=1;
do
{
if(a==b)
{

break;
}
if(a%b++==0)
flag = 0;

}while(b<a/2);
b=2;
if (flag)
{
cout<<" "<<a;
}
a++;
}while(a<=100);


return 0;
}


```

##2-32

```cpp
#include<iostream>
#include<stdlib.h>
using namespace std;
int main(){
int a = 1+rand()%100;
int b;
while(true){
cin>>b;
if (b==a){
cout<<"猜对啦";break;}
else if(b<a)
cout<<"太小了"<<endl;
else
cout<<"太大了"<<endl;
}
return 0;
}
```

##2-34

#include<iostream>
using namespace std;
int main(){
int i,j,k,n,m=0;
cout<<"请输入不同颜色的球数:";
cin>>n;
cout <<"1是红 2是黄 3是蓝 4白 5是黑..."<<endl;
for (i=1;i<=n-2;i++){
for(j=i+1;j<=n-1;j++){
for(k=j+1;k<=n;k++){
cout<<i<<j<<k<<endl;
m++;
}
}
}
cout<<"共有"<<m<<"种";
return 0;
}

 

posted @ 2018-03-24 11:58  YYWZS  阅读(120)  评论(0编辑  收藏  举报