1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#include <iostream>
#include <cassert>
using namespace std;
int mymaximum(int a[], int numberOfElements); //prototype
int main()
{
int a[] = {12,0,-9,13,7,76};
assert(mymaximum(a,6)== 76);
int b[] = {13,0,7,98};
assert(mymaximum(b,4)== 98);
int c[] = {0,0,0,13};
assert(mymaximum(c,4)== 13);
int d[] = {-1,0,3,12};
assert(mymaximum(d,4)== 12);
int e[] = {-9092,14,1,13,0};
assert(mymaximum(e,5)== 14);
int f[] = {-1,9800,3,12,-9006};
assert(mymaximum(f,5)== 9800);
int g[] = {88,1,1,88};
assert(mymaximum(g,4)== 88);
cout << "All tests have successfully passed." << endl;
}
int mymaximum(int a[], int numberOfElements)
{
int max = a[0];
for(int i=1;i<numberOfElements;++i)
{
if(a[i] > max)
{
max = a[i];
}
}
return max;
}
|