Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Bài 11: biến vt ở hàm main cón có công dụng nào khác không ? nếu không có thì để nó trong hàm xóa phần tử là được rồi, mắc mớ gì để //ở bên ngoài hàm main cho nó rắc rối thêm
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- void Nhapmang(int **pa, int *pn)
- {
- printf("Nhap vao so luong phan tu cua mang : ");
- scanf("%d", pn);
- *pa = (int *)malloc((*pn) * sizeof(int));
- int *p = NULL;
- for (p = *pa; p < *pa + *pn; p++)
- {
- printf("Nhap a[%d] :", p - *pa);
- scanf("%d", p);
- }
- }
- void Xoaphantu(int **pa, int *pn)
- {
- int vt;
- printf("\nNhap vao vi tri muon xoa: ");
- scanf("%d",&vt);
- int *p = NULL;
- for (p = *pa + vt; p < *pa + *pn - 1; p++)
- {
- *p = *(p + 1);
- }
- (*pn)--;
- *pa = (int *)realloc(*pa, *pn * sizeof(int));
- }
- void Xuatmang(int *a, int n)
- {
- int *p = NULL;
- for (p = a; p < a + n; p++)
- {
- printf("%5d", *p);
- }
- }
- int main()
- {
- int *a = NULL;
- int n;
- Nhapmang(&a, &n);
- printf("Mang vua nhap la : \n");
- Xuatmang(a, n);
- Xoaphantu(&a, &n);
- Xuatmang(a, n);
- free(a);
- a = NULL;
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement