Answer to Question #226794 in C++ for Ter

Question #226794

write a c++ program that creates a one dimentional array with of length 5. Your program should read 5 integers from the keyboard into the array. You are to perform sequential search for an integer in the array and push the location of the element sought for on to a stack.


1
Expert's answer
2021-08-17T12:54:36-0400


#include <iostream>




using namespace std;




int main()
{
    int arr[5];
    cout<<"Enter five numbers\n";
    for(int i=0; i<5; i++){
        cin>>arr[i];
    }
    cout<<"\nThe elements of the array are: \n";
    for(int i=0; i<5; i++){
        cout<<arr[i]<<"\t";
    }
    int n;
    cout<<"\nEnter the number to find\n";
    cin>>n;
    int index;
    for(int i=0; i<5; i++){
        if(arr[i]== n){
            
            index = i;
            cout<<"The number is found at location "<<(i+1)<<endl;
        }
        else{
            cout<<" "<<endl;
        }
    }
    int n2;
    cout<<"Enter the new number \n";
    cin>>n2;
    arr[index] = n2;
    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