用穷举法找出1~100中的质数
代码:
using namespace std; int main() { int k = 1; for (int i = 1; i <= 99; i++) { k++; int a = 0; for (int j = 2; j <= i / 2; j++) { if (k% j == 0) { a = 1; } } if (a != 1) { cout << k; cout << " "; } } return 0; }
例2-29
代码:
using namespace std; int main() { srand((unsigned int)time(NULL)); int a = rand() % 100 + 1;//生成1~100的随机数 int b; do { cin >> b; if (a < b) { cout << "大了" << endl; } else if (a > b) { cout << "小了" << endl; } else cout << "猜对了" << endl; } while (a != b); return 0; }
例2-31
代码部分:
#include<iostream> #include<time.h> using namespace std; int main() { int k, f; for (int i = 1; i <= 9; i++) { for (int j = 1; j <= 9; j++) { cout << i << "*" << j << "="<<i*j<<" "; } cout << endl; } return 0; }
标签:std,main,int,namespace,using,习题,第二章,部分,100 From: https://www.cnblogs.com/xuechenhao173/p/17312166.html