关于c primer plus 第五版 动态内存例题问题
/*dyn_arr.c--为数组动态分配存储空间*/# include <stdio.h>
# include <stdlib.h> //为malloc()和free ()函数提供原型
int main(void)
{
double *ptr;
int max;
int number;
int i = 0;
puts("What is the maximum number of type double entries?");
scanf("%d",&max);
ptr = (double *)malloc (max *sizeof(double));
if(ptr == NULL)
{
puts("Memory allocation failed. Goodbye.");
exit(EXIT_FAILURE);
}
/*ptr 现在指向有max个元素的数组*/
puts("Enter the values(q to quit):");
while (i < max && scanf("%lf",&ptr[i])==1)
++i;
printf("Here are your %d entries: \n",number = i);
for (i = 0; i < number; i++)
{
printf("%7.2f",ptr[i]);
if(i % 7 == 6)
putchar('\n');
}
if(i % 7 != 0)
putchar('\n');
puts("Done.");
free(ptr);
return 0;
}
问题:
"
if(i % 7 == 6)
putchar('\n');
}
if(i % 7 != 0)
putchar('\n');
puts("Done.");
free(ptr);
" 为什么要除7, 判断 等于6?