S1E24打印直方图
#include <stdio.h>int main()
{
float pm = {{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 = {0};
float max = 0, min = 100;//
for (i = 0;i < 3;i++)
{
for (j = 0;j < 12;j++)
{
if (pm)
{
max = (pm > max) ? pm : max;
min = (pm < min) ? pm : min;
}
n = (pm-20)/0.5; // 计算*个数
// printf("i = %d, j = %d, n = %d \n", i, j, n);
}
}
printf("最小值:%.2f, 最大值:%.2f\n", min, max);
for (i = 0;i < 3;i++);
{
for (j = 0;j < 12;j++)
{
if (n > 0) //剔除未录入的数据
{
// printf("%d年%2d月:", i+2014, j+1);
// for (k = 0;k < n;k++)
// {
// printf("*");
// }
// printf("\n");
printf("i = %d, j = %d, n = %d \n", i, j, n);
}
}
}
return 0;
}
请问我定义的二维数组n在输出的时候位什么会出现i = 3的情况,应该如何修改呢? 本帖最后由 jhq999 于 2021-9-28 16:11 编辑
#include <stdio.h>
int main()
{
float pm = {{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 = {0};
float max = 0, min = 100;//
for (i = 0;i < 3;i++)
{
for (j = 0;j < 12;j++)
{
if (pm)
{
max = (pm > max) ? pm : max;
min = (pm < min) ? pm : min;
}
n = (pm-20)/0.5; // 计算*个数
// printf("i = %d, j = %d, n = %d \n", i, j, n);
}
}
printf("最小值:%.2f, 最大值:%.2f\n", min, max);
for (i = 0;i < 3;i++)//////////////////////////////////////////;你多打了个分号
{
for (j = 0;j < 12;j++)
{
if (n > 0) //剔除未录入的数据
{
// printf("%d年%2d月:", i+2014, j+1);
// for (k = 0;k < n;k++)
// {
// printf("*");
// }
// printf("\n");
printf("i = %d, j = %d, n = %d \n", i, j, n);
}
}
}
return 0;
}
页:
[1]