#include <iostream> using namespace std; int main() { char n; std::cout<<"Menu: A(dd) D(elete) S(ort) Q(uit) Select one:\n"; while(n!='Q') { std::cin>>n ; if(n=='A') std::cout <<"数据已经增加\n"; if(n=='D') std::cout <<"数据已经删除\n"; if(n=='S') std::cout <<"数据已经排序\n"; std::cout << "Menu: A(dd) D(elete) S(ort) Q(uit) Select one:\n"; } return 0; }
输入Q的时候
2-28-2
#include <iostream> using namespace std; int main(){ char n; std::cout <<"Menu: A(dd) D(elete) S(ort) Q(uit) Select one:\n"; cin>>n; while(n!='Q') { switch(n) { case 'A': std::cout <<"数据已经增加\n";break; case 'D': std::cout<<"数据已经删除\n";break; case 'S': std::cout<<"数据已经排序\n";break; case 'Q':break; } std::cout <<"Menu: A(dd) D(elete) S(ort) Q(uit) Select one:\n"; cin >>n; } return 0; }
输入Q的时候
2-29-1
#include <iostream> using namespace std; int main() { int j,i,m,n; 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<<" "; i++; } return 0; }
2-29-2
#include <iostream> int main() { int j,i,m,n; i=2; for(;i<101;i++) {m=1;n=i/2;j=2; for(;j<=n;j++) { if(i%j==0) {m=0; break; }j++; } if(m) std::cout<<i<<" "; } return 0; }
2-29-3
#include <iostream> int main() { int j,i,m,n; i=2; do {m=1;n=i/2;j=2; while(j<=n) { if(i%j==0) {m=0; break; }j++; } if(m) std::cout<<i<<" "; i++; }while(i<101); return 0; }
2-32
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { int n; int guessnumber; srand(time(nullptr)); n=rand()%100+1;//1~200随机生成的一个数。 cout<<n; while(n!=guessnumber) {cout<<"you guess number is (1~100):\n"; cin>>guessnumber; if(guessnumber>n) cout<<"bigger than the number"<<endl; else if(guessnumber<n)cout<<"smaller than the number"<<endl; else cout<<"成功猜对"<<endl; } return 0; }
2-32-2
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { int n; int guessnumber; srand(time(nullptr)); n=rand()%100+1;//1~200随机生成的一个数。 cout<<n; do {cout<<"you guess number is (1~100):\n"; cin>>guessnumber; if(guessnumber>n) cout<<"bigger than the number"<<endl; else if(guessnumber<n)cout<<"smaller than the number"<<endl; else cout<<"成功猜对"<<endl; }while(n!=guessnumber); return 0; }
2-34
#include <iostream> using std::cout; using std::endl; int fun(int m,int n)//函数调用 {if(m==n)return 1; if(n==0) return 1; return fun(m-1,n-1)+fun(m-1,n); } int main() {cout<<fun(5,3)<<endl;}