| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 359 人关注过本帖
标题:关于c primer plus 第五版 动态内存例题问题
取消只看楼主 加入收藏
司空云襄
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-6-12
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:0 
关于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?
搜索更多相关主题的帖子: allocation include Memory double number 
2015-06-12 16:20
快速回复:关于c primer plus 第五版 动态内存例题问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011636 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved