본문 바로가기
코딩/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;
}

'코딩 > C++' 카테고리의 다른 글

다중 포인터와 동적 다차원 배열  (0) 2024.03.10
void 포인터  (0) 2024.03.10
참조 변수 Reference Variable  (0) 2024.03.09
const 포인터  (0) 2024.03.09
동적할당(new, delete)  (0) 2024.03.08