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

}

}

相关推荐
QuantumStack42 分钟前
【C++ 真题】P1104 生日
开发语言·c++·算法
whoarethenext1 小时前
使用 C++/OpenCV 和 MFCC 构建双重认证智能门禁系统
开发语言·c++·opencv·mfcc
代码的奴隶(艾伦·耶格尔)2 小时前
后端快捷代码
java·开发语言
Jay_5152 小时前
C++多态与虚函数详解:从入门到精通
开发语言·c++
路来了2 小时前
Python小工具之PDF合并
开发语言·windows·python
xiaolang_8616_wjl3 小时前
c++文字游戏_闯关打怪
开发语言·数据结构·c++·算法·c++20
WJ.Polar3 小时前
Python数据容器-list和tuple
开发语言·python
small_wh1te_coder3 小时前
硬件嵌入式学习路线大总结(一):C语言与linux。内功心法——从入门到精通,彻底打通你的任督二脉!
linux·c语言·汇编·嵌入式硬件·算法·c
FrostedLotus·霜莲3 小时前
C++主流编辑器特点比较
开发语言·c++·编辑器
超级码.里奥.农3 小时前
零基础 “入坑” Java--- 七、数组(二)
java·开发语言