C + + Experiment Two

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.