C++实验一

时间:2023-03-09 15:15:06
C++实验一

2-28

#include <iostream>
using namespace std;
int main()
{char x;
cout<<"Menu: A(dd) D(elete) S(ort) Q(uit),Select one:"<<endl;
cin>>x;
while(x)
{if (x=='A')
{cout<<"Date add"<<endl;
}
else
if (x=='D')
{cout<<"Date delete"<<endl;
}
else
if (x=='S')
{cout<<"Date sort"<<endl;
}
else if(x=='Q')
break;
else cout<<"Date error"<<endl;
cout<<"Menu: A(dd) D(elete) S(ort) Q(uit),Select one:"<<endl;
cin>>x;
}
return ;
}

(1)

C++实验一

#include <iostream>
using namespace std;
int main()
{char x;
cout<<"Menu: A(dd) D(elete) S(ort) Q(uit),Select one:"<<endl;
cin>>x;
while(x)
{switch(x)
{case 'A':
cout<<"Date add"<<endl;
break;
case 'D':
cout<<"Date delete"<<endl;
break;
case 'S':
cout<<"Date sort"<<endl;
break;
default:
cout<<"Date quit"<<endl; }
if(x=='Q')
break;
cout<<"Menu: A(dd) D(elete) S(ort) Q(uit),Select one:"<<endl;
cin>>x;
}
return ;
}

(2)

C++实验一

2-29

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int t = , i, j = , flag;
while (j < )
{
flag = ;
i = ;
while (i <= j - )
{
if (j%i++ == )
{
flag = ;
break;
}
}
if (flag == )
{
t++;
cout << setw()<<j ;
if (t % == )
cout << endl;
}
j++;
}
return ;
}

(1)

C++实验一

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int t = , i, j = , flag;
do
{
flag = ;
i = ;
while (i <= j - )
{
if (j%i++== )
{
flag = ;
break;
}
}
if (flag == )
{
t++;
cout << setw() << j;
if (t % == )
cout << endl;
}
j++;
}while (j < );
return ;
}

(2)

C++实验一

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int t = , i, j = , flag;
for (;j < ;j++)
{
flag = ;
i = ;
for (;i <= j - ;i++)
{
if (j%i== )
{
flag = ;
break;
}
}
if (flag == )
{
t++;
cout << setw() << j;
if (t % == )
cout << endl;
}
}
return ;
}

(3)

C++实验一

2-32

#include <iostream>
using namespace std;
int main()
{int i=, j;
cin >> j;
while (i != j)
{
if (j > i)
cout << "bigger than the number" << endl;
if (j < i)
cout << "lower than the number" << endl;
cin >> j;
}
cout <<"Congratulations!You guess it."<< endl;
return ;
}

(1)

C++实验一

#include <iostream>
using namespace std;
int main()
{
int i = , j;
cin >> j;
do
{
if (j > i)
cout << "bigger than the number" << endl;
if (j < i)
cout << "lower than the number" << endl;
cin >> j;
}while (i != j);
cout << "Congratulations!You guess it." << endl;
return ;
}

(2)

C++实验一

2-34

#include<iostream>
using namespace std;
int main()
{int a, b, c;
cout << "red:0,yellow:1,blue:2,white:3,black:4"<<endl;
for (a = ;a < ;a++)
{
for (b = a + ;b < ; b++)
{
if (a == b) continue;
for (c = b + ;c < ;c++)
{
if (c == a || c == b) continue;
cout << a << b << c << endl;
}
}
}
return ;
}

(0)

C++实验一

总结:要好好学习,加油鸭~

https://www.cnblogs.com/syf1/p/10561928.html

https://www.cnblogs.com/fearless04/p/10543040.html

https://www.cnblogs.com/Yyaoyyy/p/10547742.html