Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- int a[20];
- int main()
- {
- int x, n, j, i, p;
- n = 19;
- // generare random
- srand(time(0));
- for(i = 0; i <= n; i++) a[i] = rand() % 3;
- // afisare
- for(i = 1; i <= n; i++) cout << a[i] << " ";
- cout << "\n";
- x = 2;
- // elimin pe x din a
- // complexitate O(n*n)
- for(i = 1; i <= n; )
- {
- if(a[i] == x)
- {
- p = i;
- for(j = p + 1; j <= n; j++) a[j - 1] = a[j];
- n--;
- }
- else i++;
- }
- for(i = 1; i <= n; i++) cout << a[i] << " ";
- cout << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment