Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
739 B
1
Indexable
Never
#include<stdio.h>
#include<stdlib.h>

void Input_Array_1D(int*& a, int& n);
void FreeArray_1D(int*& a);
void OutputArray_1D(int* a, int n);

void main()
{
	int n;
	do {
		printf("\nNhap vao so luong phan tu cua mang: ");
		scanf_s("%d", &n);
	} while (n < 0);

	int *a = (int*)malloc(n * sizeof(int));

	printf("\n---Nhap vao cac phan tu cua mang-----\n");
	Input_Array_1D(a, n);

	OutputArray_1D(a, n);

	FreeArray_1D(a);
}

void Input_Array_1D(int*& a, int& n)
{	
	for (int i = 0; i < n; i++)
	{
		printf("\na[%d]= ", i);
		scanf_s("%d", &a[i]);
	}
}

void OutputArray_1D(int* a, int n)
{
	for (int i = 0; i < n; i++)
	{
		printf("%4d", a[i]);
	}
}

void FreeArray_1D(int*& a)
{
	free(a);
}