Advertisement
huutho_96

Untitled

Mar 10th, 2015
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "conio.h"
  3. int kiemtrasnt(int n)
  4. {
  5. for (int i = sqrt(float(n)); i >= 2; i--)
  6. if (n % i == 0) return 0;
  7. if(n > 1) return 1;
  8. else return 0;
  9. }
  10. void xoa(int a[], int k, int &n)
  11. {
  12. for (int i = k; i < n - 1; i++)
  13. {
  14. a[i] = a[i + 1];
  15. }
  16. n--;
  17. }
  18. void xoant(int a[], int &n)
  19. {
  20.  
  21. for (int i = 0; i < n; i++)
  22. if (kiemtrasnt(a[i]) == 1) xoa(a, i, n);
  23. }
  24. int timk(int a[], int k, int n)
  25. {
  26. int dem = 0;
  27. for (int i = 0; i < n; i++)
  28. if (a[i] == k) dem++;
  29. return dem;
  30. }
  31. int main(void)
  32. {
  33. int n, b, k, m;
  34. printf("Nhap n: ");
  35. scanf_s("%d.\n", &n);
  36. int *a = new int[n];
  37. for (int i = 0; i < n; i++)
  38. {
  39. printf("nhap phan tu thu %d: ", i + 1);
  40. scanf("%d.\n", &a[i]);
  41. }
  42. for (int i = 0; i < n; i++)
  43. printf("%d\t", a[i]);
  44. printf("\n1.Xoa so nguyen to\n2.Liet ke so phan tu bang k\nLua chon: ");
  45. scanf("%d.\n", &b);
  46. switch (b)
  47. {
  48. case 1:
  49. xoant(a, n);
  50. for (int i = 0; i < n; i++)
  51. printf("%d\t", a[i]);
  52. break;
  53. case 2:
  54. printf("\nNhap k: ");
  55. scanf("%d.\n", &k);
  56. m = timk(a, k, n);
  57. printf("So phan tu bang k: %d\n", m);
  58. if (m % 3 != 0) printf("khong ");
  59. printf("chia het\n");
  60. break;
  61. default:
  62. break;
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement