LA is an array with 10 elements. Your task is to write a C++ program that will perform
sequential search for an element and compute the sum of squares of the location of the
element sought for
using namespace std;
#include <omp.h>
#include <stdio.h>
/*
LA is an array with 10 elements. Your task is to write a C++ program that will perform
sequential search for an element and compute the sum of squares of the location of the
element sought for
*/
main(void)
{
int LA[10] = {23, 34, 12, 45, 67, 78, 89, 64, 31, 90};
int i,j=0,n;
cout<<"\nInput Array LA is given as:";
for(i=0;i<10;i++) cout<<"\tLA["<<i<<"] = "<<LA[i]<<endl;
cout<<"\nEnter a number to search for: "; cin>>n;
for(i=0;i<10;i++)
{
if(n==LA[i])
{
cout<<"\nNumber found as\tLA["<<i<<"] = "<<LA[i]<<endl;
cout<<"Square of location index = "<<i*i;
j=1;
}
}
if(j==0) cout<<"\n\tNumber not found.";
}
Comments
Leave a comment