Answer to Question #226823 in C++ for Johnnie

Question #226823
LA is an array with 10 elements. Your task is to write an algorithm that will perform

sequential search for an element and compute the sum of squares of the location of the

element sought for
1
Expert's answer
2021-08-17T12:54:27-0400
#include <iostream>
using namespace std;
int main(){
    int LA[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    cout<<"Enter number to search for: ";
    int p; cin>>p;
    bool found = false;
    for(int i = 0; i < 10; i++){
        if(LA[i] == p){
            cout<<"Found at location "<<i<<"\n";
            found = true;
            p = i;
            break;
        }
    }
    if(found){
        cout<<"Square of the location: "<<p * p;
    }
    else cout<<"Element not found";
    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