Advertisement
Guest User

StergeElemente

a guest
Oct 17th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. void sterge(int v[],int &n,int i,int j)
  7. {
  8.     int oldn=n,st,dr;
  9.  
  10.     st=i;
  11.     dr=j;
  12.     n=n-(dr-st+1); ///modific nr de elem
  13.     for(int poz = st ; poz<=oldn ;poz++){
  14.         if(poz+(dr-st+1)<=oldn){
  15.            v[poz] = v[poz+(dr-st+1)]; ///mut toate elem cu dr-poz+1 pozitii spre stanga
  16.         }
  17.     }
  18. }
  19.  
  20. int main()
  21. {
  22.     int n,a[1001],k=0;
  23.     cin>>n;
  24.     for(int i=1;i<=n;i++){
  25.         cin>>a[i];
  26.     }
  27.     sterge(a,n,2,4); ///apelul
  28.  
  29.     for(int i=1;i<=n;i++){
  30.         cout<<a[i]<<" ";
  31.     }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement