/*c语言动态数组,运行时确定数组元素个数。*/
#include <stdio.h>
#include <malloc.h>

int main(void)
{
	int *p;
	int n;

	/*运行时分配内存*/
	scanf("%d", &n);
	p = (int *)malloc(sizeof(int) * n);

	/*输入数组元素*/
	int i;
	for (i = 0; i < n; i++) {
		scanf("%d", &p[i]);
	}

	/*输出数组元素*/
	int j;
	for (j = 0; j < n; j++) {
		printf("%d ", p[j]);
	}

	free(p);

	return 0;
}

相关文章:

  • 2022-03-01
  • 2021-05-30
  • 2021-12-06
  • 2021-11-05
  • 2022-12-23
  • 2019-10-27
  • 2022-12-23
  • 2021-07-10
猜你喜欢
  • 2021-03-27
  • 2021-06-12
  • 2021-09-01
  • 2021-11-05
  • 2022-12-23
  • 2021-12-06
相关资源
相似解决方案