Advertisement
Rehan_Rahman26

Function Related Problem 5

Oct 7th, 2021
746
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int del(int arr[], int n, int x)
  5. {
  6. int i;
  7. for (i=0; i<n; i++)
  8.     if (arr[i] == x)
  9.         break;
  10.  
  11. if (i < n)
  12. {
  13.  
  14.     n = n - 1;
  15.     for (int j=i; j<n; j++)
  16.         arr[j] = arr[j+1];
  17. }
  18.  
  19. return n;
  20. }
  21.  
  22. int main()
  23. {
  24.     int arr[] = {11, 15, 6, 8, 9, 10};
  25.     int n = sizeof(arr)/sizeof(arr[0]);
  26.     int x = 6;
  27.  
  28.     n = del(arr, n, x);
  29.  
  30.     cout << "Modified array is \n";
  31.     for (int i=0; i<n; i++)
  32.     cout << arr[i] << " ";
  33.  
  34.     return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement