#include <iostream>
using namespace std;
int main()
{
char n;
cout<<"Menu: A(dd) D(elete) S(ort) Q(uit),Select one: "<<endl;
cin>>n;
while(1)
{
while(n!=‘Q‘)
{
switch(n)
{
case ‘A‘:
{
cout<<"数据已经增加"<<endl;break;
}
case ‘D‘:
{
cout<<"数据已经删除"<<endl;break;
}
case ‘S‘:
{
cout<<"数据已经排序"<<endl;break;
}
}
cin>>n;
}
}
return 0;
}
png98.8kB
//用while编程
#include <iostream>
using namespace std;
int main () {
int i,j,n,m;
i=2;
while(i<101)
{
m=1,n=i/2;j=2;
while(j<=n)
{
if(i%j==0)
{
m=0;
break;
}
j++;
}
if(m)
cout<<i<<endl;
i++;
}
}
//用do while 编程
#include<iostream>
using namespace std;
int main()
{
int i,j,n,m;
i=2;
do
{
m=1;
n=i/2;
j=2;
do
{
if(i%j==0)
{
m=0;
break;
}
j++;
}
while(j<=n);
if(m)
cout<<i<<" ";
i++;
}
while(i<101);
return 0;
}
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int i,m;
double n;
for(i=2;i<101;i++)
{
n=sqrt(i);
for(m=2;m<n;m++)
{
if(i%m==0)break;
}
if(m>n)
cout<<i<<endl;
}
return 0;
}
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main()
{
int x;
srand(time(0));
int number=rand()%100+1;
cout<<"猜一下这个数: ";
cin>>x;
while(1)
{
if(x!=number)
{
if(x<number)
{
cout<<"小了"<<endl;
}
else
{
cout<<"大了"<<endl;
}
}
else
{
cout<<"恭喜猜对了!"<<endl;break;
}
cin>>x;
}
return 0;
}
#include<iostream>
using namespace std;
int take(int ,int );
int main()
{
int k;
k=take(5,3);
cout<<"球的取法为"<<k;
return 0;
}
int take(int n,int k)
{
if(k>n)
return 0;
else if(n==k||k==0)
return 1;
else if(n>k)
return take(n-1,k)+take(n-1,k-1);
}