Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void deleteArgFromArr(int * arr, const int size, int argument) {
- int counter = 0;
- for (int i = 0; i < size; i++)
- {
- if (arr[i] == argument )
- {
- for (int k = i; k < size - 1; k++)
- {
- arr[k] = arr[k + 1];
- }
- counter++;
- break;
- }
- }
- if (counter == 0)
- {
- cout << "No such element exists in your array!" << endl;
- }
- else
- {
- cout << "The element has been deleted successfully!" << endl;
- cout << "New array: " << endl;
- for (int i = 0; i < size - 1; i++)
- {
- cout << arr[i] << " ";
- }
- cout << endl;
- }
- }
- void adElemEnd(int * arr, const int size, int elem) {
- for (int i = 0; i < size; i++)
- {
- if (i == size - 1)
- {
- arr[i] = elem;
- break;
- }
- }
- cout << "The new arr is: " << endl;
- for (size_t i = 0; i < size; i++)
- {
- cout << arr[i] << " ";
- }
- cout << endl;
- }
- void elemAtPos(int * arr, const int size, int elem, int atPosition) {
- for (int i = 0; i < size; i++)
- {
- if (i == atPosition)
- {
- for (int j = size; j > i; j--)
- {
- arr[j] = arr[j-1];
- }
- arr[atPosition] = elem;
- break;
- }
- }
- cout << "The new arr is: " << endl;
- for (int i = 0; i < size; i++)
- {
- cout << arr[i] << " ";
- }
- cout << endl;
- }
- int main() {
- //подточка А)
- /*const int num = 10;
- int arr[num] = { 1,2,3,4,5,6,7,8,9,10 };
- cout << "Enter the num you wish to be deleted: ";
- int numToDel;
- cin >> numToDel;
- deleteArgFromArr(arr, num, numToDel);*/
- //подточка В)
- /*const int size = 11;
- int arr[size] = { 1,2,3,4,5,6,7,8,9,10 };
- int elem;
- cin >> elem;
- adElemEnd(arr, size, elem);*/
- //подточка С)
- const int size = 11;
- int myArr[size] = { 1,2,3,4,5,6,7,8,9,10,0};
- int elem, position;
- cin >> elem >> position;
- elemAtPos(myArr, size, elem, position);
- //подточка D)
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement