1.Write a program to insert a particular number in an array.
1
Expert's answer
2013-02-18T08:44:49-0500
#include <conio.h> #include <iostream>
using namespace std;
void insert_element(int* array, int arraySize, int pos, int element) { if (pos < 0 || pos >= arraySize) { cout << "Invalid insertion position: " << pos << endl; return; }
/* Shift array elements right starting from the $pos index */ for (int k = arraySize - 1; k > pos; k--) array[k] = array[k - 1]; array[pos] = element; }
void print_array(int* array, int arraySize) { for (int c = 0; c < arraySize; c++) cout << " " << array[c]; cout << endl; }
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments