Created
April 12, 2019 15:53
-
-
Save winhtut/268a683bf5c72e527d6971e376023858 to your computer and use it in GitHub Desktop.
Array delete
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include<conio.h> | |
| using namespace std; | |
| int main() | |
| { | |
| int data[10]; | |
| int number = 0; | |
| int dElete = 0; | |
| int position = 0; | |
| int found = 1; | |
| cout << "Please insert number of element :"; | |
| cin >> number; | |
| for (int i = 0; i < number; i++) { | |
| cout << "Enter element at index- " << i << " ;"; | |
| cin >> data[i]; | |
| } | |
| cout << "The data of the elements are"; | |
| for (int x = 0; x < number; x++) { | |
| cout << " "<<data[x]; | |
| } | |
| cout << endl; | |
| cout << "Enter the element to be delete"; | |
| cin >> dElete; | |
| for (int y = 0; y < number; y++) { | |
| if (data[y] == dElete) { | |
| position = y; | |
| found = 1; | |
| break; | |
| } | |
| } | |
| if (found == 1) { | |
| for (int p = position; p < number; p++) { | |
| data[p] = data[p + 1]; | |
| } | |
| cout << "The result after deleted is:"; | |
| for (int z = 0; z < number; z++) { | |
| cout << data[z]; | |
| } | |
| } | |
| else | |
| { | |
| cout << "The data is not found in the element" << endl; | |
| } | |
| _getch(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment