c++ - 如何找到 10x12 矩阵的最小值和最大值
问题描述
我有一个使用 10x12 矩阵计算销售公司销售额的程序。
销售公司在 10 个城市设有分公司,程序必须打印每个分公司在过去 12 个月内的销售数量。然后打印当年的总销售额,那么最后就是打印销售额的最小值和最大值
但是程序没有打印正确的最小值和最大值
这是代码
using namespace std;
int main() {
double F[10][12];
double sum[10] = { 0 };
double Msum[12] = { 0 };
int i = 0;
int j;
double x = 0;
double max = 0;
double Minimum = 100000000;
for (i = 0; i < 10; i++) {
cout << "please enter the " << i + 1 << " branch sale for the " << endl;
for (j = 0; j < 12; j++) {
cout << "month " << j + 1 << ": " << endl;
cin >> F[i][j];
}
}
for (i = 0; i < 10; i++)
for (j = 0; j < 12; j++)
sum[i] += F[i][j];
for (i = 0; i < 10; i++) {
cout << "the total sales for branch " << i + 1 << " is " << sum[i] << endl;
}
for (i = 0; i < 10; i++)
for (j = 0; j < 12; j++) {
x += F[i][j];
}
cout << "the total sales for all branches in the year is " << x << endl;
int min = INT_MAX;
int max = INT_MIN;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j <= 3 / 2; j++)
{
if (F[i][j] > F[i][3 - j - 1])
{
if (min > F[i][3 - j - 1])
min = F[i][3 - j - 1];
if (max < F[i][j])
max = F[i][j];
}
else
{
if (min > F[i][j])
min = F[i][j];
if (max < F[i][3 - j - 1])
max = F[i][3 - j - 1];
}
}
}
cout << "the branch that has the maximum sale in the year is " << max << endl;
cout << "the month that has the least sales in the year is " << min << endl;
return 0;
}```
解决方案
推荐阅读
- ios - 如何在使用 UIPageControl 时调整 UIView 的大小以填充 UIScrollView 的内容
- sql - 如何在另一个表中查找缺少属性 ID 的记录 ID
- html - 在 xPath 中使用 AND 和 NOT
- bootstrap-4 - Parsley JS 不适用于引导选择
- python - 赋值前引用的局部变量 - 令牌确认
- android - 使用 FusedLocationProviderClient 模拟和 Koin 进行依赖注入的单元测试
- git - git checkout 的声明式管道函数
- asp.net - 如何将请求时间设置为几个小时 - IIS 和 ASP:NET
- kubernetes - PriorityClass 不会将其值填充到 podSpec
- php - 如何根据php mysql中的id更新一行的总和