用c++ 设计算法并编写程序,定义、输入10行10列二维数组,分别求其中大于等于60和小于60的元素个数
时间: 2023-07-15 20:12:52 浏览: 39
以下是一个简单的实现:
```c++
#include <iostream>
using namespace std;
int main() {
const int ROWS = 10;
const int COLS = 10;
int arr[ROWS][COLS];
// 输入二维数组
cout << "请输入10行10列的二维数组:" << endl;
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
cin >> arr[i][j];
}
}
// 统计大于等于60和小于60的元素个数
int greaterCount = 0;
int lessCount = 0;
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
if (arr[i][j] >= 60) {
greaterCount++;
} else {
lessCount++;
}
}
}
// 输出结果
cout << "大于等于60的元素个数:" << greaterCount << endl;
cout << "小于60的元素个数:" << lessCount << endl;
return 0;
}
```
输入样例:
```
90 80 70 60 50 40 30 20 10 0
0 10 20 30 40 50 60 70 80 90
90 80 70 60 50 40 30 20 10 0
0 10 20 30 40 50 60 70 80 90
90 80 70 60 50 40 30 20 10 0
0 10 20 30 40 50 60 70 80 90
90 80 70 60 50 40 30 20 10 0
0 10 20 30 40 50 60 70 80 90
90 80 70 60 50 40 30 20 10 0
0 10 20 30 40 50 60 70 80 90
```
输出样例:
```
大于等于60的元素个数:50
小于60的元素个数:50
```
相关推荐
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)