ToniDev

Stergere element pozitie data vector

Dec 9th, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #define MAX_SIZE 70
  5.  
  6. int main()
  7. {
  8.     int v[MAX_SIZE];
  9.     int n;
  10.  
  11.     cout << "Introdu n (mai mic decat " << MAX_SIZE << "): ";
  12.     cin >> n;
  13.    
  14.  
  15.     //Inserare
  16.     int a;
  17.     for (int i = 0; i < n; i++)
  18.     {
  19.         cout << "Introdu valoare: ";
  20.         cin >> a;
  21.  
  22.         v[i] = a;
  23.     }
  24.  
  25.  
  26.     //Afisare
  27.     for (int i = 0; i < n; i++)
  28.     {
  29.         cout << v[i] << " ";
  30.     }
  31.  
  32.     cout << endl;
  33.  
  34.     int pozitie_de_sters;
  35.  
  36.     cout << "Introdu pozitia de unde doresti sa stergi elementul: ";
  37.     cin >> pozitie_de_sters;
  38.  
  39.     for (int i = pozitie_de_sters; i < n; i++)
  40.     {
  41.         v[i] = v[i + 1];
  42.     }
  43.  
  44.     n--;
  45.  
  46.     //Afisare
  47.     for (int i = 0; i < n; i++)
  48.     {
  49.         cout << v[i] << " ";
  50.     }
  51.  
  52.     return 0;
  53. }
  54.  
  55.  
Advertisement
Add Comment
Please, Sign In to add comment