6. C++ Program to delete an element from an Array(Element)

#include<iostream> using namespace std; int main() { int arr[10],n,elem,pos; cout<<“How many elements you want to insert = “; cin>>n; cout<<“Enter data in an Array :: “; for(int i = 0;i<n;i++) { cin>>arr[i]; } cout<<“Enter Element you want to Delete”; cin>>elem; for(int i =0;i<n;i++) { if(elem == arr[i]) { pos= i; for(int j = pos;j<n;j++) arr[j]…

6. C++ Program to delete an element from an Array(Position)

#include<iostream> using namespace std; int main() { int arr[10],n,pos; cout<<“How many elements you want to insert = “; cin>>n; cout<<“Enter data in an Array :: “; for(int i = 0;i<n;i++) { cin>>arr[i]; } cout<<“Enter Position you want to Delete”; cin>>pos; if(pos>10){ cout<<“Position doesn’t Exist”; } else{ for(int i = pos-1;i<n;i++) arr[i] = arr[i+1]; n =…

6. C++ Program to delete an element from an Array(Last Element)

#include<iostream> using namespace std; int main() { int arr[10],n,elem; cout<<“How many elements you want to insert = “; cin>>n; cout<<“Enter data in an Array :: “; for(int i = 0;i<n;i++) { cin>>arr[i]; } cout<<“Deleting Last element of an Array :: “; n = n-1 ; cout<<“\n\nArray after Deleting :: \n”; for(int i = 0;i<n;i++) {…

6. C++ Program to delete an element from an Array(First Element)

#include<iostream> using namespace std; int main() { int arr[10],n,elem; cout<<“How many elements you want to insert = “; cin>>n; cout<<“Enter data in an Array :: “; for(int i = 0;i<n;i++) { cin>>arr[i]; } cout<<“Deleting first element of an Array :: “; for(int i=0;i<n;i++) { arr[i] = arr[i+1]; } n = n-1 ; cout<<“\n\nArray after Deleting…

5. C++ program to insert an element in an array (At given Position)

#include<iostream> using namespace std; int main() { int arr[10],n,elem,pos; cout<<“How many elements you want to insert = “; cin>>n; cout<<“Enter data in an Array :: “; for(int i = 0;i<n;i++) { cin>>arr[i]; } cout<<“Enter Position and element you want to insert in Last Position”; cin>>pos>>elem; if(pos>10){ cout<<“Position is Out of Range”; } else{ for(int i…

5. C++ program to insert an element in an array (Last Position)

#include<iostream> using namespace std; int main() { int arr[10],n,elem; cout<<“How many elements you want to insert = “; cin>>n; cout<<“Enter data in an Array :: “; for(int i = 0;i<n;i++) { cin>>arr[i]; } cout<<“Enter element you want to insert in Last Position”; cin>>elem; arr[n] = elem; n = n+1 ; cout<<“\n\nArray after Insertion :: \n”;…

5. C++ program to insert an element in an array (First Position)

#include<iostream> using namespace std; int main() { int arr[10],n,elem; cout<<“How many elements you want to insert = “; cin>>n; cout<<"Enter data in an Array :: "; for(int i = 0;i>arr[i]; } cout<<“Enter element you want to insert in First Position”; cin>>elem; for(int i=n;i>0;i–) { arr[i] = arr[i-1]; } arr[0] = elem; n = n+1 ;…

4. C++ program to reverse the element of an integer 1-D array

#include<iostream> using namespace std; int main() { // Reverse of an array int num, temp; cin>>num; int arr[num]; for(int i = 0;i<num ;i++) cin>>arr[i]; for(int i = 0, j=num-1; i<j;i++,j–) { temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } cout<<"\nElements of an array after Reverse :: \n"; for(int i = 0;i<num ;i++) cout<<arr[i]<"\t";…

2. C++ program to swap first and last element of an integer 1-d array.

#include<iostream> using namespace std; int main() { int n, temp; cout<<“Enter Number of elements you want to enter :: “; cin>>n; int arr[n]; for(int i = 0;i<n;i++){ cin>>arr[i]; } temp = arr[0]; arr[0] = arr[n-1]; arr[n-1] = temp; cout<<“Array after swapping first and last elements “<<endl; for(int i = 0;i<n;i++){ cout<<arr[i]<<“\t”; } return 0; }