Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- #include "conio.h"
- int kiemtrasnt(int n)
- {
- for (int i = sqrt(float(n)); i >= 2; i--)
- if (n % i == 0) return 0;
- if(n > 1) return 1;
- else return 0;
- }
- void xoa(int a[], int k, int &n)
- {
- for (int i = k; i < n - 1; i++)
- {
- a[i] = a[i + 1];
- }
- n--;
- }
- void xoant(int a[], int &n)
- {
- for (int i = 0; i < n; i++)
- if (kiemtrasnt(a[i]) == 1) xoa(a, i, n);
- }
- int timk(int a[], int k, int n)
- {
- int dem = 0;
- for (int i = 0; i < n; i++)
- if (a[i] == k) dem++;
- return dem;
- }
- int main(void)
- {
- int n, b, k, m;
- printf("Nhap n: ");
- scanf_s("%d.\n", &n);
- int *a = new int[n];
- for (int i = 0; i < n; i++)
- {
- printf("nhap phan tu thu %d: ", i + 1);
- scanf("%d.\n", &a[i]);
- }
- for (int i = 0; i < n; i++)
- printf("%d\t", a[i]);
- printf("\n1.Xoa so nguyen to\n2.Liet ke so phan tu bang k\nLua chon: ");
- scanf("%d.\n", &b);
- switch (b)
- {
- case 1:
- xoant(a, n);
- for (int i = 0; i < n; i++)
- printf("%d\t", a[i]);
- break;
- case 2:
- printf("\nNhap k: ");
- scanf("%d.\n", &k);
- m = timk(a, k, n);
- printf("So phan tu bang k: %d\n", m);
- if (m % 3 != 0) printf("khong ");
- printf("chia het\n");
- break;
- default:
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement