Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <iomanip>
- using namespace std;
- int kt_trung(int *a, int n, int x)
- {
- int i;
- if (n>0)
- {
- i = n/2;
- if (x==a[i]) return 1;
- else
- if (x>a[i]) return kt_trung(&a[i+1],n-1-i,x);
- return kt_trung(a,i,x);
- }
- return 0;
- }
- main()
- {
- int n,i;
- do {
- cout << "Nhap so phan tu: "; cin >> n;
- } while(n<=0);
- int *a = new int [n];
- for (i=0; i<n; )
- {
- cout << "Nhap a[" << i+1 << "]: ";
- cin >> a[i];
- if (kt_trung(a,i,a[i])==0) i++;
- }
- cout << endl <<"Day da nhap: " << endl;
- for (i=0; i<n; i++)
- cout << setw(6) << a[i];
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement