Insert Values in Specific Index of Array using C++
=======================================================================
#include<iostream>
using namespace std;
main()
{
int arr[10]={10,20,40,55,60,70,80,90};
int k,n=8,item;
cout<<"Enter Index Number\n";
cin>>k;//Enter Index number
cout<<"\nEnter Value You want to Insert\n";
cin>>item;// Enter value to Insert
for(int j=n;j>=k;j--)
{
arr[j+1]=arr[j];
}
arr[k]=item;//set index K=item
n++;
cout<<"New Array value\n";
for(int j=0;j<10;j++)
{
cout<<arr[j]<<" ";
}
cout<<endl;
system("pause");
}
========================================================================
0 comments:
Post a Comment