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

Expert's answer

#include <iostream>
using namespace std;
int main(){
    int LA[10] = {12345678910};
    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;
}
LATEST TUTORIALS
APPROVED BY CLIENTS