Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
557 B
15
Indexable
Never
#include<iostream>
using namespace std;

void Input_Array_1D(int*& a, int& n)
{
	for (int i = 0; i < n; i++)
	{
		cout << "a[" << i << "]= ";
		cin >> a[i];
	}
}
void FreeArray_1D(int*& a)
{
	delete[]a;
}
void OutputArray_1D(int* a, int n)
{
	for (int i = 0; i < n; i++)
	{
		cout << a[i] <<" ";
	}
}

void main()
{
	int n;
	do {
		cout << "\nNhap vao so luong phan tu cua mang: " ;
		cin >> n;
	} while (n < 0);

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

	Input_Array_1D(a, n);
	OutputArray_1D(a, n);
	FreeArray_1D(a);
}