gpt4 book ai didi

c - 我无法显示最大 PSI 值对应的区域

转载 作者:行者123 更新时间:2023-11-30 21:05:01 25 4
gpt4 key购买 nike

我无法在所有区域中显示我对应的最高 PSI 读数的区域。

我尝试了许多其他各种方法,但无法显示最高 PSI 值的相应区域(中部、东部、北部、南部、西部......)。

我已在每个区域的数组中声明了 PSI 值。

int i, largest;

int Time[] = { 600,700,800,900,1000,1100,1200,1300,1400,1500,1600,1700,1800 };
int Central[] = { 89,88,87,143,139,79,144,85,83,90,89,88,76 };
int East[] = { 80,79,78,77,76,80,90,89,88,110,109,143,136 };
int North[] = { 147,144,141,139,137,132,109,110,109,80,77,132,108 };
int South[] = { 90,89,88,139,136,132,102,105,109,110,109,80,77 };
int West[] = { 141,137,153,147,143,83,90,89,141,138,134,130,127 };

largest = Central[0];
for (i = 1; i < 13; i++)
{
if (largest < Central[i])
largest = Central[i];
}
largest = Central;

for (i = 0; i < 13; i++)
{
if (largest < East[i])
largest = East[i];
}
for (i = 0; i < 13; i++)
{
if (largest < North[i])
largest = North[i];
}
for (i = 0; i < 13; i++)
{
if (largest < South[i])
largest = South[i];
}
for (i = 0; i < 13; i++)
{
if (largest < West[i])
largest = West[i];
}
printf(" Highest PSI value amongst all is %d\n\n\n", largest);
break;

我能够显示最大的 PSI 值,但无法显示该最高 PSI 值的区域。

例如,如果我的数组中最大的 PSI 是 180,位于 Central,则会显示 PSI 值为 180,对应区域为 Central。

如果我的数组中最大的PSI是180,即在西部,它将显示PSI值为180,对应的区域是西部。

最佳答案

  1. 将数组分配给 int :largest = Central;
  2. 您需要创建一个包含区域名称的变量,并在每次 PSI 较大时更新它。您所要做的就是在最后打印它。这给了我们:
    #include <stdio.h>

int i, largest;
char *region = NULL;

int Time[] = { 600,700,800,900,1000,1100,1200,1300,1400,1500,1600,1700,1800 };
int Central[] = { 89,88,87,143,139,79,144,85,83,90,89,88,76 };
int East[] = { 80,79,78,77,76,80,90,89,88,110,109,143,136 };
int North[] = { 147,144,141,139,137,132,109,110,109,80,77,132,108 };
int South[] = { 90,89,88,139,136,132,102,105,109,110,109,80,77 };
int West[] = { 141,137,153,147,143,83,90,89,141,138,134,130,127 };


largest = Central[0];
for (i = 1; i < 13; i++) {
if (largest < Central[i]) {
largest = Central[i];
region = "Central";
}
}
for (i = 0; i < 13; i++) {
if (largest < East[i]) {
largest = East[i];
region = "East";
}
}
for (i = 0; i < 13; i++) {
if (largest < North[i]) {
largest = North[i];
region = "North";
}
}
for (i = 0; i < 13; i++) {
if (largest < South[i]) {
largest = South[i];
region = "South";
}
}
for (i = 0; i < 13; i++) {
if (largest < West[i]) {
largest = West[i];
region = "West";
}
}
printf(" Highest PSI value amongst all is %d in %s\n\n\n", largest, region);

关于c - 我无法显示最大 PSI 值对应的区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57166064/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com