-
Notifications
You must be signed in to change notification settings - Fork 0
/
maxelement.c
49 lines (44 loc) · 1.08 KB
/
maxelement.c
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
//=======================================================================
// Copyright (c) 2014 Kiriakos Velissariou
// Distributed under the MIT License.
// (See accompanying file LICENSE or copy at
// http://opensource.org/licenses/MIT)
//=======================================================================
#include<stdio.h>
#define MAX 100
int size;
int getMaxElement(int myarr[]){
static int i = 0, max = -9999;
if(i < size){
if(max < myarr[i]){
max = myarr[i];
}
i++;
getMaxElement(myarr);
}
return max;
}
int getMinElement(int myarr[]){
static int i = 0, min = 9999;
if(i < size){
if(min > myarr[i]){
min = myarr[i];
}
i++;
getMinElement(myarr);
}
return min;
}
int main(){
int myarr[MAX], max, min, i;
printf("Please enter the size of the array: ");
scanf("%d", &size);
printf("Enter the elements of the array: ");
for(i = 0; i < size; i++){
scanf("%d", &myarr[i]);
}
max = getMaxElement(myarr);
min = getMinElement(myarr);
printf("The largest element of the array is: %d\n", max);
printf("The smallest element of the array is: %d", min);
}