Answer to Question #225596 in C++ for Ulando

Question #225596

Write a c++ program that create a one dimensional array with of length5.your program should read 5 integers from the keyboard into the array. Your to perform sequential search for an integer in the array and insert a new item in that location of the array.


1
Expert's answer
2021-08-12T16:25:16-0400


#include <iostream>


using namespace std;


int main()
{
    int arr[5];
    cout<<"Enter the five integers of the array\n";
    for(int i=0; i<5; i++){
        cout<<"Enter integer number "<<(i+1)<<endl;
        cin>>arr[i];
    }
    cout<<"\nThe elements of the array are: \n";
    for(int i=0; i<5; i++){
        cout<<arr[i]<<"\t";
    }
    int number;
    cout<<"\nEnter the number to find\n";
    cin>>number;
    int index;
    for(int i=0; i<5; i++){
        if(arr[i]== number){
            
            index = i;
            cout<<"The number is found at location "<<(i+1)<<endl;
        }
        else{
            cout<<" "<<endl;
        }
    }
    int number2;
    cout<<"Enter the new number \n";
    cin>>number2;
    arr[index] = number2;
    cout<<"The final array after the insertion of the new integer is: \n";
    for(int i=0; i<5; i++){
        cout<<arr[i]<<"\t";
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS