Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*scrieti un program ce sa gaseasca nr de elemente mai mari ca x dintr-un tablou unidimensional cu metoda DEI*/
- #include <iostream>
- using namespace std;
- void read(int &n, int v[]) {
- cout << "n=";cin >> n;
- for (int i = 0; i < n; i++) {
- cout << "v[" << i << "]=";
- cin >> v[i];
- }
- }
- int check(int v[], int p, int q, int x) {
- if (p > q)
- return 0;
- int mid = (p + q) / 2;
- return check(v, p, mid - 1, x) + check(v, mid + 1, q, x) + (v[mid] > x);
- }
- int main() {
- int n, v[1000], x;
- read(n, v);
- cout << "x=";cin >> x;
- cout << check(v, 0, n - 1, x);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement