An algorithm to delete an specefic element of an array.

###An algorithm to delete an specefic element of an array.
Flowchart given below:
Source Code In C++:

#include <stdio.h>
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
  int i,j,k,count;
  int a[100];
  std::cout << "How many elements: ";
  std::cin >> count;
  std::cout << "Take the elements of the array" << '\n';
  for (size_t i = 0; i < count; i++) {
  std::cin >> a[i];
  }
  std::cout << "The position you wanna delete: " ;
  std::cin >> k;
  std::cout << "After deleting the element ,the sorted array:" << '\n';

  for (size_t i = 0; i <k-1; i++) {
    std::cout <<a[i] << '\n';
  }
  for (size_t i =k; i <count; i++) {
    std::cout << a[i] << '\n';
  }
  return 0;
}


Output:
 How many elements: 5
Take the elements of the array
1
2
3
4
5
The position you wanna delete: 2
After deleting the element ,the sorted array:
1
3
4
5

Press any key to continue . . .



Explanation:
Here we were asked for deleting an element of an array.So we just took the position of the array we wanna delete and then we printed all the elements ignoring the element we wanna delete.









No comments

Powered by Blogger.