코딩/C++
for-each 반복문
by sonysame
2024. 3. 10.
#include <iostream>
#include <limits>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
//int fibonacci[] = { 0,1,1,2,3,5,8,13,21,34,55,89 };
vector<int> fibonacci= { 0,1,1,2,3,5,8,13,21,34,55,89 };
//for (int& number : fibonacci)number = 10;
for (auto& number : fibonacci)number = 10;
for (int number : fibonacci)cout << number << " ";
cout << endl;
int max_number = std::numeric_limits<int>::lowest(); //limits
cout << max_number << endl;
for (const auto& n : fibonacci)
max_number = std::max(max_number, n); //algorithm
cout << max_number << endl;
return 0;
}