1 개요[ | ]
- C++ array_max()
C++
Copy
#include <iostream>
#include <algorithm>
#define ARRAYSIZE(A) sizeof(A)/sizeof((A)[0])
int main() {
int nums[] = {3, 6, 2, 8, 1};
int max = *std::max_element(nums,nums+ARRAYSIZE(nums));
std::cout << max; // 8
}
Loading
C++
Copy
#include <iostream>
#define ARRAYSIZE(A) sizeof(A)/sizeof((A)[0])
int array_max(int a[], int size) {
int max = a[0];
for(int i=1; i<size; i++) if(a[i]>max) max=a[i];
return max;
}
int main() {
int nums[] = {3, 6, 2, 8, 1};
int size = ARRAYSIZE(nums);
int max = array_max(nums, size);
std::cout << max; // 8
}
Loading
C++
Copy
#include <iostream>
#include <array>
#include <algorithm>
int main() {
std::array<int,5> arr = {3, 6, 2, 8, 1};
int max = *std::max_element(arr.begin(),arr.end());
std::cout << max; // 8
}
Loading
2 같이 보기[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.