#include \n\nvoid findMaxElement(int a[], int size, int& maxElement, int& maxIndex) { \n maxElement = a[0]; \n maxIndex = 0; \n\n for (int i = 1; i < size; i++) { \n if (a[i] > maxElement) { \n maxElement = a[i]; \n maxIndex = i; \n } \n } \n} \n\nint main() { \n int a[5] = {5, -1, 0, 7, 2}; \n int maxElement, maxIndex; \n\n findMaxElement(a, 5, maxElement, maxIndex); \n\n std::cout << "最大元素:" << maxElement << std::endl; \n std::cout << "最大元素的序号:" << maxIndex << std::endl; \n\n return 0; \n}

C++ 一维数组最大元素和序号查找函数实现

原文地址: https://www.cveoy.top/t/topic/pnSh 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录