Cho em hỏi sao em không xuất ra được giá trị chẵn ạ :((
Dùng con trỏ trong C ạ.
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
//Ham nhap
void nhap(int*p,int n)
{
int i;
for(i=0;i<n;i++)
{
printf("\nPhan tu thu %d:",i);
scanf("%d",p+i);
}
}
//Ham xuat
void xuat(int*p,int n)
{
int i;
for(i=0;i<n;i++)
printf("%5d",*(p+i));
}
//Ham xuat so chan
void xuatc(int *p, int n)
{
printf("\nPhan tu chan trong mang la: ");
int i, d=0;
for(i=0; i<n; i++)
{
if(*(p+i)%2==0)
{
d++;
}
}
if(d==0)
printf("\nMang khong co phan tu chan");
else
printf("%d",*(p+i));
}
//Ham main
int main()
{
int *p,n,i;
do{
printf("\nNhap so phan tu mang: ");
scanf("%d",&n);}
while(n<1||n>100);
p=(int*)malloc(n*sizeof(int));
nhap(p,n);
printf("\nMang vua nhap la: \n");
xuat(p,n);
xuatc(p,n);
getch();
}