C Primer Plus(第六版)16.18 编程练习 第7题

#include <stdio.h>

#include <stdlib.h>

#include <stdarg.h>

void show_array(const double ar[] ,int n) ;

double * new_d_array(int n, ...) ;

int main ()

{

double * p1;

double * p2;

p1 = new_d_array(5, 1.2,2.3, 3.4, 4.5, 5.6);

p2 = new_d_array(4, 100.0, 20.00, 8.08, -1890.0);

show_array(p1,5);

show_array(p2,4);

free(p1);

free(p2);

return 0;

}

double * new_d_array(int n, ...)

{

double *p = NULL;

p = (double *)malloc(sizeof(double)*n);

va_list ap;

va_start(ap,n);

for(int i=0;i<n;i++)

{

*(p+i)=va_arg(ap,double);

}

return p;

}

void show_array(const double ar[] ,int n)

{

printf("数组:%p\n",ar);

for(int i=0;i<n;i++)

{

printf("第%d个元素:%lf \n",i,ar[i]);

}

}

相关推荐
通信仿真实验室26 分钟前
(10)MATLAB莱斯(Rician)衰落信道仿真1
开发语言·matlab
勿语&29 分钟前
Element-UI Plus 暗黑主题切换及自定义主题色
开发语言·javascript·ui
代码雕刻家3 小时前
数据结构-3.9.栈在递归中的应用
c语言·数据结构·算法
吾爱星辰4 小时前
Kotlin 处理字符串和正则表达式(二十一)
java·开发语言·jvm·正则表达式·kotlin
ChinaDragonDreamer4 小时前
Kotlin:2.0.20 的新特性
android·开发语言·kotlin
IT良4 小时前
c#增删改查 (数据操作的基础)
开发语言·c#
Kalika0-05 小时前
猴子吃桃-C语言
c语言·开发语言·数据结构·算法
_.Switch5 小时前
Python Web 应用中的 API 网关集成与优化
开发语言·前端·后端·python·架构·log4j
代码雕刻家5 小时前
课设实验-数据结构-单链表-文教文化用品品牌
c语言·开发语言·数据结构
一个闪现必杀技5 小时前
Python入门--函数
开发语言·python·青少年编程·pycharm