Write a program that creates an array which can hold ten values. Fill the array
ID: 3725485 • Letter: W
Question
Write a program that creates an array which can hold ten values. Fill the array with random numbers from 1 to 200. Display the values in the array on the screen. Then use a linear search to find the largest value in the array, and display that value. Write a program that creates an array which can hold ten values. Fill the array with random numbers from 1 to 200. Display the values in the array on the screen. Then use a linear search to find the largest value in the array, and display that value.Explanation / Answer
#include<iostream>
#include<cstdlib>
using namespace std;
//you have not specified which language it is .... but this oode will help you with logic
//i have written with basic syntax...
//hope you get it....
//in case you didn't get...
//comment..language...i will provide code for that
int main()
{
int a[10];//creating array with size 10;
//generating 10 random numbers
int i;
for(i=0;i<10;i++)
{
a[i]=rand()%200+1;//random number between 1 and 200
}
//diplaying values... of array
cout<<"Array :";
for(i=0;i<10;i++)//to traverse array
{
cout<<a[i]<<" ";
}
cout<<" ";
//linear search to find largest...value...
int large = a[0];//initially setting largest value to the first value of array
for(i=0;i<10;i++)//to traverse array
{
if(a[i]>large)//updating large value
large = a[i];
}
//printng large value
cout<<"Largest value: "<<large<<endl;
return 0;
}
output:
Array :42 68 135 101 170 125 79 159 163 65
Largest value: 170
Process exited normally.
Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.