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]);

}

}

相关推荐
学会去珍惜1 天前
是什么意思c语言
c语言·编程语言·底层开发·面向过程·系统软件
t***5441 天前
Clang 编译器在 Orwell Dev-C++ 中的局限性
开发语言·c++
oy_mail1 天前
QoS质量配置
开发语言·智能路由器·php
oyzz1201 天前
PHP操作redis
开发语言·redis·php
nashane1 天前
HarmonyOS 6学习:网络能力变化监听与智能提示——告别流量偷跑,打造贴心网络感知应用
开发语言·php·harmony app
凌波粒1 天前
Java 8 “新”特性详解:Lambda、函数式接口、Stream、Optional 与方法引用
java·开发语言·idea
handler011 天前
拒绝权限报错!三分钟掌握 Linux 权限管理
linux·c语言·c++·笔记·学习
拾贰_C1 天前
【Google | Gemini | API | POST】怎么使用Google 的Gemini API (原生版)
开发语言·lua
t***5441 天前
如何在Dev-C++中选择Clang编译器
开发语言·c++