Untitled
unknown
plain_text
3 years ago
852 B
6
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* a, n; Input_Array_1D(a, n); OutputArray_1D(a, n); FreeArray_1D(a); } void Input_Array_1D(int*& a, int& n) { do { printf("\nNhap vao so luong phan tu cua mang: "); scanf_s("%d", &n); if (n < 0) { printf("\nso luong khong hop le !, vui long nhap lai"); } } while (n < 0); a = (int*)malloc(n * sizeof(int)); printf("\n---Nhap vao cac phan tu cua mang-----\n"); if (a == NULL) return; 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); }