|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
int main()
{
float pm[3][12] = {{0,0,0,0,0,0,0, 31.3, 35.5, 58.7, 49.6, 55.5},
{59.8, 54.9, 33.1, 38.2, 26.6, 20.5, 27.8, 38.5, 41.5, 44.7, 38.1, 41.5},
{34.9, 36.4, 47.5, 37.9, 30.6, 23.4, 26.6, 34.3}};
int i, j, k;
int n[3][12] = {0};
float max = 0, min = 100;//
for (i = 0;i < 3;i++)
{
for (j = 0;j < 12;j++)
{
if (pm[i][j])
{
max = (pm[i][j] > max) ? pm[i][j] : max;
min = (pm[i][j] < min) ? pm[i][j] : min;
}
n[i][j] = (pm[i][j]-20)/0.5; // 计算*个数
// printf("i = %d, j = %d, n[i][j] = %d \n", i, j, n[i][j]);
}
}
printf("最小值:%.2f, 最大值:%.2f\n", min, max);
for (i = 0;i < 3;i++);
{
for (j = 0;j < 12;j++)
{
if (n[i][j] > 0) //剔除未录入的数据
{
// printf("%d年%2d月:", i+2014, j+1);
// for (k = 0;k < n[i][j];k++)
// {
// printf("*");
// }
// printf("\n");
printf("i = %d, j = %d, n[i][j] = %d \n", i, j, n[i][j]);
}
}
}
return 0;
}
请问我定义的二维数组n在输出的时候位什么会出现i = 3的情况,应该如何修改呢?
本帖最后由 jhq999 于 2021-9-28 16:11 编辑 #include <stdio.h>
int main()
{
float pm[3][12] = {{0,0,0,0,0,0,0, 31.3, 35.5, 58.7, 49.6, 55.5},
{59.8, 54.9, 33.1, 38.2, 26.6, 20.5, 27.8, 38.5, 41.5, 44.7, 38.1, 41.5},
{34.9, 36.4, 47.5, 37.9, 30.6, 23.4, 26.6, 34.3}};
int i, j, k;
int n[3][12] = {0};
float max = 0, min = 100;//
for (i = 0;i < 3;i++)
{
for (j = 0;j < 12;j++)
{
if (pm[i][j])
{
max = (pm[i][j] > max) ? pm[i][j] : max;
min = (pm[i][j] < min) ? pm[i][j] : min;
}
n[i][j] = (pm[i][j]-20)/0.5; // 计算*个数
// printf("i = %d, j = %d, n[i][j] = %d \n", i, j, n[i][j]);
}
}
printf("最小值:%.2f, 最大值:%.2f\n", min, max);
for (i = 0;i < 3;i++)//////////////////////////////////////////;你多打了个分号
{
for (j = 0;j < 12;j++)
{
if (n[i][j] > 0) //剔除未录入的数据
{
// printf("%d年%2d月:", i+2014, j+1);
// for (k = 0;k < n[i][j];k++)
// {
// printf("*");
// }
// printf("\n");
printf("i = %d, j = %d, n[i][j] = %d \n", i, j, n[i][j]);
}
}
}
return 0;
}
|
-
|