-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathmax_till_i.cpp
More file actions
40 lines (34 loc) · 615 Bytes
/
max_till_i.cpp
File metadata and controls
40 lines (34 loc) · 615 Bytes
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
/*
Given an array a[] of size n. For every i from 0 to n-1. Output max(a[0],a[1]...)
*/
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int maxOfArray(const int* arr, int n)
{
int max = *arr;
for(int i =0; i<n; i++)
{
if(*(arr+i)>max)
{
max = *(arr+i);
}
}
return max;
}
int main()
{
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++)
{
int num;
cin >> num;
arr[i] = num;
}
int max = maxOfArray(arr, n);
cout<<"Max of array: "<<max<<endl;
return 0;
}