[b]#include[/b] <stdio.h>
[b]#include[/b] <conio.h>
[b]#include[/b] <malloc.h>
[b]void[/b] NhapDaySo(int *,int);
[b]int *[/b]SoChiaHetCho3(int *,int);
[b]void[/b] InDaySo(int *);
[b]int[/b] t;
[b]int[/b] main()
{
[b]int[/b] n;
[b]int *[/b]ptr_n;
[b]int *[/b]ptr_chiahetcho3;
printf("So luong so muon nhap vao:");
//ptr_n = malloc(n*sizeof(int)); [b]Chổ này sai[/b]
/*Sửa*/ptr_n
=([b
]int *[/b
])malloc(n
*sizeof(int));
//ptr_chiahetcho3 = malloc(sizeof(int)); [b]Tương tự chổ này sai [/b]
/*Sửa*/ ptr_chiahetcho3
=(int *)malloc(sizeof(int));
NhapDaySo(ptr_n,n);
ptr_chiahetcho3 = SoChiaHetCho3(ptr_n,n);
// printf("Nhung so chia het cho 3 la:");} [b]chổ này dư }[/b]
printf("Nhung so chia het cho 3 la:");
InDaySo(ptr_chiahetcho3);
getch();
return 0;
}
[b]void[/b] NhapDaySo(int *ptr,int n)
{
[b]int[/b] i;
for(i=0;i<n;i++)
{
printf("Nhap So Thu %d :",i
+1); }
}
[b]int[/b] *SoChiaHetCho3(int *ptr,int n)
{
[b]int[/b] i,j=0;
[b]int[/b] *ptr_chiahetcho3;
//ptr_chiahetcho3 = malloc(sizeof(int)); [b]Chổ này sai[/b]
[b
]/*Sửa*/[/b
]ptr_chiahetcho3
=(int *)malloc(sizeof(int)); for(i=0;i<n;i++)
{
if(ptr[i]%3==0)
{
j++;
//ptr_chiahetcho3 = realloc(ptr_chiahetcho3,j * sizeof(int)); [b]Sai[/b]
[b
]/*Sửa*/[/b
]ptr_chiahetcho3
= (int*)realloc(ptr_chiahetcho3
,j
* sizeof(int)); ptr_chiahetcho3[j] = ptr[i];
t++;
}
}
return ptr_chiahetcho3;
}
[b]void[/b] InDaySo(int *ptr)
{
[b]int[/b] i;
for(i=0;i<t;i++)
{
}
}