Write an algorithm to read 100 numbers then display the largest.
#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;
}
Comments
Leave a comment