Answer to Question #199658 in Algorithms for Munyangabo junior

Question #199658

Write an algorithm to read 100 numbers then display the largest.


1
Expert's answer
2021-05-27T19:12:35-0400


#include <vector>
#include <iostream>

int LargestElement(const std::vector<int>& data)
{
  int result = data[0];
  for(auto item : data)
    if (item > result)
      result = item;
  return result;
}

int main() {
  
  std::vector<int> data;
  for (int i = 0; i < 100; ++i)
  {
    int number;
    std::cin >> number;
    data.push_back(number);
  }
  std::cout << LargestElement(data);
  return 0;
}

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