/function prototypes (Youshould put necessary function prototypes here.) int mai
ID: 3617996 • Letter: #
Question
/function prototypes (Youshould put necessary function prototypes here.)
int main()
{
//call functionusing prototype: dataType FindLargest(const dataTypeanArray[], int size);
//output results toverify your answer
//Sample output:
return 0;
}//end of main
//---------------
dataType FindLargest(const dataType anArray[], int size)
{
//declare local variables and initialize the variables fortesting
//assume the first element is the largest
largest = anArray[0];
//check each of the remaining elements to find largest
for(index = 1;index < size;index++)
{
//compare current largest to an array element andupdate largest if necessary
if(//is an array element larger than currentlargest
anArray[index] > largest)
{
largest = anArray[index];
}
}
return largest;
}
Explanation / Answer
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int FindMax(const int anArray[], int size);
int main(){
int arr[] = {10,9,2,3,2,9,1,0,-1,900};
int size = 10;
int largest = FindMax(arr,size);
cout << "The largest is " << largest << " ";
system("pause");
return 0;
}
int FindMax(const int anArray[], int size){
int index;
//assume the first element is the largest
int largest = anArray[0];
//check each of the remaining elements to find largest
for(index = 1;index < size;index++){
//compare the current largest to an array element and update largest if necessary
//is an array element smaller than current largest
if(anArray[index] > largest){
largest = anArray[index];
}
}
return largest;
} Java2html #include <iostream>
#include <fstream>
#include <string>
using namespace std;
int FindMax(const int anArray[], int size);
int main(){
int arr[] = {10,9,2,3,2,9,1,0,-1,900};
int size = 10;
int largest = FindMax(arr,size);
cout << "The largest is " << largest << " ";
system("pause");
return 0;
}
int FindMax(const int anArray[], int size){
int index;
//assume the first element is the largest
int largest = anArray[0];
//check each of the remaining elements to find largest
for(index = 1;index < size;index++){
//compare the current largest to an array element and update largest if necessary
//is an array element smaller than current largest
if(anArray[index] > largest){
largest = anArray[index];
}
}
return largest;
} Java2html Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.