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 0; }
#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 0; }
2-29
#include <iostream> #include <iomanip> using namespace std; int main() { int t = 0, i, j = 2, flag; while (j < 100) { flag = 1; i = 2; while (i <= j - 1) { if (j%i++ == 0) { flag = 0; break; } } if (flag == 1) { t++; cout << setw(5)<<j ; if (t % 5 == 0) cout << endl; } j++; } return 0; }
#include <iostream> #include <iomanip> using namespace std; int main() { int t = 0, i, j = 2, flag; do { flag = 1; i = 2; while (i <= j - 1) { if (j%i++== 0) { flag = 0; break; } } if (flag == 1) { t++; cout << setw(5) << j; if (t % 5 == 0) cout << endl; } j++; }while (j < 100); return 0; }
#include <iostream> #include <iomanip> using namespace std; int main() { int t = 0, i, j = 2, flag; for (;j < 100;j++) { flag = 1; i = 2; for (;i <= j - 1;i++) { if (j%i== 0) { flag = 0; break; } } if (flag == 1) { t++; cout << setw(5) << j; if (t % 5 == 0) cout << endl; } } return 0; }
2-32
#include <iostream> using namespace std; int main() {int i=66, 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 0; }
#include <iostream> using namespace std; int main() { int i = 66, 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 0; }
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 = 0;a < 5;a++) { for (b = a + 1;b < 5; b++) { if (a == b) continue; for (c = b + 1;c < 5;c++) { if (c == a || c == b) continue; cout << a << b << c << endl; } } } return 0; }
总结:要好好学习,加油鸭~
https://www.cnblogs.com/syf1/p/10561928.html
https://www.cnblogs.com/fearless04/p/10543040.html
https://www.cnblogs.com/Yyaoyyy/p/10547742.html