1.
(1)
#include <iostream>
using namespace Std;
int main ()
{
char i;
cout<< "Menu:a (DD) D (elete) S (ORT) Q (uit)" <<endl;
while (true)
{
cin>>i;
if (i== ' A ')
cout<< "Data has been increased" <<endl;
else if (i== ' D ')
cout<< "Data has been deleted" <<endl;
else if (i== ' S ')
cout<< "Data is sorted" <<endl;
else if (i== ' Q ')
Break
}
return 0;
}
(2)
#include <iostream>
using namespace Std;
int main ()
{
char i;
cout<< "Menu:a (DD) D (elete) S (ORT) Q (uit)" <<endl;
while (true)
{
cin>>i;
switch (i) {
Case ' A ':
cout<< "Data has been increased" <<endl;continue;
Case ' D ':
cout<< "Data has been deleted" <<endl;continue;
Case ' S ':
cout<< "Data is sorted" <<endl;continue;
Case ' Q ':
break;}
}
return 0;
}
2.
(1)
To determine whether a number is prime, you need to divide the number k from 1 to square root k, and if no number can be divisible, then K is prime, and vice versa.
(2)
#include <iostream>
#include <cmath>
#include <stdlib.h>
using namespace Std;
int main ()
{
int k,i;
cout<< "prime number between 1~100" <<endl;
for (k=2;k<=100;k++)
{
For (I=2;i<=sqrt (k); i++)
{
if (k%i==0)
Break
}
if (I>=sqrt (k))
cout<<k<<endl;
}
System ("pause");
return 0;
}
3.
#include <iostream>
#include <cstdlib>
using namespace Std;
int main ()
{
cout<< "Please guess a number between 1 and 100,i would tell you whether it's higher or lower" <<endl;
int x, y;
X=rand ()%100;
cin>>y;
while (y!=x) {
if (y>x) {
cout<< "Lower" <<endl;
Cin>>y;continue;}
else{
cout<< "Higher" <<endl;
Cin>>y;continue;}
}
cout<< "Yes!" <<endl;
return 0;
}
3.
#include <iostream>
#include <cstdlib>
using namespace Std;
int main ()
{
Using the idea of permutation combination is known as 5*4/(2*1), it can be understood that in 5 colors choose two not to take, first in 5 Select one, and then in the remaining 4 selected 1.
int t,x,y;
for (X=1;X<=5;++X)
for (Y=x+1;y<=5;++y)
++t;
cout<< "have" <<t<< "seed";
return 0;
}
Summarize:
Feel that their learning is not very good, a lot of it is to turn over a number of books, think for a long time, and then still in the help of students to complete, found that some statements know but do not understand how the actual application of the program, after the practice.
C + + Experiment Two