所以我有一个Array,我应该计算索引1到5的平均值。索引0和6用于另一个目的。有人可以帮我从这里出去吗?

码:

int jumpnr = 0;
int jumpval[7];

for (jumpval=0; jumpval<7; jumpval++){
jumpnr = jumpnr++
printf("Enter the jumpdistance for the %d",jumpnr);
scanf(%d,&jumpval);
}

int average = jumpval[1] -> [5]; // <------- ? how
printf("The average jumpdistance is: %d",average);

最佳答案

用伪代码会像

initialize an int called 'sum' and set it to 0
for i from jumpval[1] to jumpval[5]
    sum+=jumpval[i]


然后将总和除以5得到的平均值。

关于c - 选择数组中的范围,C,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33633433/

10-10 23:51