구문에 다소 문제가 있습니다. 아래 프로그램의 목적은 20 개의 난수 배열을 인쇄하고 배열의 최대 값을 찾은 다음 배열과 최대 값을 인쇄하는 것입니다. 나는 초기화하고 문제없이 배열을 만드는 섹션을 가지고 있지만, 내 문제는 find_max 함수입니다. main 함수에서 find_max 함수를 호출하여 결과를 출력 할 수있는 구문을 작성하려고합니다. 누구든지 내 구문을 고치는 데 도움을 줄 수 있다면 정말 고맙겠습니다.배열을 매개 변수로 사용하는 조정 함수
는#include <cstdlib>
#include <iostream>
using
namespace std;
void
init_array(int array[], int size, int range)
{
for (int index = 0; index < size; index++)
array[index] = rand() % range;
}
void print_array(int array[], int size)
{
for (int index = 0; index < size; index++)
cout << array[index] << " ";
cout << endl;
}
int find_max (int array[], int size)
{
int max = array[0];
for (int index = 0; index < size; index++)
{
if (array[index] > max)
max = array[index];
}
return max;
}
int main()
{
// Declare array of integers
const int size = 20;
int array[size] = {0};
int max = find_max(array,size);
// Initialize and print array
init_array(array, size, 100);
print_array(array, size);
cout << "The max is:" << max << endl;
return 0 ;
}
그랬어! 도와 주셔서 감사합니다! – Lumberjacked216