gpt4 book ai didi

C - 如何显示数组中低于数组中数字平均值的数字

转载 作者:行者123 更新时间:2023-11-30 18:49:41 25 4
gpt4 key购买 nike

#include <stdio.h>
#include <stdlib.h>

void main()
{
int i=0;
int ray[20];
float sum=0.00, average;

for (i=0; i<20; i++)
{
printf("Enter integer #%d",i+1);
scanf ("%d", &ray[i]);
sum=(sum+ray[i]);
}

average=(sum/20);
printf("Average = %.2f", average);

if (ray[i] < average)
{
printf("The followiing values are less than the average: %d", ray[i]);
}
system("pause");
}

代码运行良好,并给出了输入整数的正确平均值,但小于平均值的值显示为 -858993460

最佳答案

您正在尝试打印 ray[i],但 i 当前为 20,位于数组索引之外。您的意思是复制 if 语句周围的 for 循环吗?

关于C - 如何显示数组中低于数组中数字平均值的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42120348/

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