Skip to content

Commit 2caa552

Browse files
Merge pull request seeditsolution#125 from Mohd97/patch-1
maxinarray
2 parents dfa009f + 149a4f0 commit 2caa552

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

maxinarray

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
#define SIZE 50 //Defining max size of array
6+
7+
int main()
8+
9+
{
10+
int array[SIZE];
11+
int i, max, min, size;
12+
// Input size of the array
13+
cout<<"Enter size of the array: ";
14+
cin>>size;
15+
// Input array elements
16+
cout<<"\n Enter "<<size <<" elements in the array: ";
17+
for(i=0; i<size; i++)
18+
cin>>array[i];
19+
// Assume first element as maximum
20+
max = array[0];
21+
22+
//Find maximum in all array elements.
23+
for(i=1; i<size; i++)
24+
{
25+
// If current element is greater than max
26+
if(array[i] > max)
27+
max = array[i];
28+
29+
}
30+
// Print maximum element
31+
cout<<"\nMaximum element =" << max << "\n";
32+
33+
return 0;
34+
35+
}

0 commit comments

Comments
 (0)