Advertisement
nguyenhappy92

Xóa tất cả các số chẵn trong mảng các số nguyên

Dec 8th, 2015
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. // Xoa cac so chan trong mang
  2. // Khai bao cac ham thu vien neu co
  3. #include<stdio.h>
  4. #include<conio.h>
  5.  
  6. #define SIZE 100
  7. void nhap(int a[],int &n)
  8. {
  9. scanf("%d",&n);
  10. for(int i=0;i<n;i++)
  11. {
  12. scanf("%d",&a[i]);
  13. }
  14. }
  15. void xoaPT(int a[],int &n,int k)
  16. {
  17. for(int i=k;i<n;i++)
  18. {
  19. a[i]=a[i+1];
  20. }
  21. n--;
  22. }
  23. void xoaChan(int a[],int &n)
  24. {
  25. for(int i=0;i<n;i++)
  26. {
  27. if((a[i])%2==0)
  28. {
  29. xoaPT(a,n,i);
  30. i--;
  31. }
  32. }
  33. }
  34. void xuat(int a[],int n)
  35. {
  36. for(int i=0;i<n;i++)
  37. {
  38. printf("%4d",a[i]);
  39. }
  40. }
  41. void main()
  42. {
  43. int a[SIZE],n;
  44. nhap(a,n);
  45. xoaChan(a,n);
  46. xuat(a,n);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement