以下代码是如何确认输入的数字是否在特定范围内的示例。
例如,如果我输入数字说 N,那么我想要增量计数器,它表示它是否在以下范围内:
1-10 11-20 ... 91-100
Here is the code snip from one of the text book:
#define MAXVAL 50
#define COUNTER 11
main ()
{
float value[MAXVAL];
int i, low, high;
static group[COUNTER] = {0,0,0,0,0,0,0,0,0,0,0}
*/READING AND COUNTING*/
for(i=0; i<MAXVAL; i++)
{
/* READING OF VALUES*/
scanf("%f", &value[i]);
/* COUNTING FREQUENCY OF GROUPS */
++group[ (int) (value[i]+0.5)/10] <<< I would like to understand how this will find if number is in specific ranges?
/* PRINTING OF FREQUENCY TABLE */
printf("\n");
printf(" GROUP RANGE FREQUENCY\N\N");
for(i=0; i< COUNTER; i++)
{
low = i*10;
if (i==10)
high =100;
else
high=low + 9;
printf( " %2d %3dto%3d %d)\n", i+1, low,high,group[i]);
}
}
这在上面的 C 程序中会做什么: ++group[ (int) (value[i]+0.5)/10]
谢谢