-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmax.cpp
More file actions
63 lines (40 loc) · 1.11 KB
/
max.cpp
File metadata and controls
63 lines (40 loc) · 1.11 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<iostream>
#include<limits.h>
using namespace std;
int main()
{
// This is the first solution without library
// int arr[] = {2 ,5 ,7, 9, 1 ,16 , 41, 100 , 1000};
// int size = 9;
// int maxNumber = arr[2]; // assume the first element of array is maximum
// for( int i = 0; i<size; i++)
// {
// if(arr[i] > maxNumber)
// {
// maxNumber = arr[i];
// }
// }
// This is the second solution with header file "limit.h"
// int arr[] = {4 ,6 ,1, 9, 8, 41, 5};
// int size = 7;
// int MaxNumber = INT_MIN;
// for(int i = 0; i<size; i++)
// {
// if(arr[i] > MaxNumber)
// {
// MaxNumber = arr[i];
// }
// }
// This is the solution to finding the minimum number of the array
int arr[] = { 2,5,7,44,88,33,99,1};
int size = 9;
int MinNumber = arr[0];
for(int i = 0; i<size; i++)
{
if(arr[i] < MinNumber)
{
MinNumber = arr[i];
}
}
cout<<"Minimum Number is "<< MinNumber<<endl;
}