Write a program that asks the user to type 10 integers of an

Write a program that asks the user to type 10 integers of an array and an integer value V and an index value i between 0 and 9. The program must put the value V at the place i in the array, shifting each element right and dropping off the last element. The program must then write the final array.

Cant get code to work properly, it copies the index into the space next to. Ive tried itierating forward and backwards just cant get this right!!!! Help!!

#include <iostream>

using namespace std;
const int size = 10;

int main()
{
    int arr[size];
    int V;
    int index;
    cout << \"Please enter 10 integers: \" << endl;
    for (int i = 0; i < size; i++)
    {
        cin >> arr[i];
    }
    cout << \"Enter V: \";
    cin >> V;
    cout<< \"Enter index\";
    cin>>index;


    for (int i = size; i > index+1; i--){

        arr[i]=arr[i-1];

    }
        arr[index]=V;
    for (int i = 0; i < size; i++){
        cout<<arr[i];
    }
    return 0;
}

Solution

#include <iostream>
using namespace std;
const int size = 10;
int main()
{
int arr[size];
int V;
int index;
  
cout << \"Please enter 10 integers: \" << endl;
for (int i = 0; i < size; i++)
{
cin >> arr[i];
}
  
cout << \"Enter V: \";
cin >> V;
  
cout<< \"Enter index\";
cin>>index;
  
cout << \"Element are before inserting element : \";
for (int i = 0; i < size; i++){
cout<<arr[i] << \" \";
}
cout << endl;
  
for (int i = size-1; i >=index+1; i--){
arr[i]=arr[i-1];
}
  
arr[index]=V;
  
cout << \"Element are after inserting element : \";
for (int i = 0; i < size; i++){
cout<<arr[i] << \" \";
}
return 0;
}

Write a program that asks the user to type 10 integers of an array and an integer value V and an index value i between 0 and 9. The program must put the value V
Write a program that asks the user to type 10 integers of an array and an integer value V and an index value i between 0 and 9. The program must put the value V

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site