max.cpp

来自「data structures, algorithms and Applicat」· C++ 代码 · 共 20 行

CPP
20
字号
// find maximum of n numbers

#include <iostream.h>

template<class T>
int Max(T a[], int n)
{// Locate the largest element in a[0:n-1].
   int pos = 0;
   for (int i = 1; i < n; i++)
     if (a[pos] < a[i])
        pos = i;
   return pos;
}

void main(void)
{
   float a[6] = {1, 2, 3, 4, 5, 6};
   cout << Max(a,6) << endl;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?