Answer to Question #226433 in C++ for Johnnie

Question #226433

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


1
Expert's answer
2021-08-16T01:03:43-0400
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.";
	
}




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