-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathquestion15.c
55 lines (33 loc) · 1.02 KB
/
question15.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
50
/*
Given an array of integers, find the maximum and minimum element from this array using a function
"void MaxMin (int arr[], int size, int *max_ptr, int *min_ptr)", where "size" denotes the number of
elements in the array. Print the maximum and minimum values from the main() function.
The array might be hard-coded in your "main()" function.
input: none
output : value of max and min from "main()".
*/
#include <stdio.h>
void MaxMin(int arr[], int size, int *max_ptr, int*min_ptr){
printf("working\n");
int j = 1;;
max_ptr = arr;
min_ptr = arr;
printf("max %d\n", *max_ptr);
printf("min %d\n", *min_ptr);
for(int i=1; i<size; i++){
j = i;
if(*max_ptr < arr[i]){
max_ptr = arr+i;
}
if(*min_ptr > arr[j]){
min_ptr = arr+j;
}
}
printf("max number is %d\n", *max_ptr);
printf("min number is %d\n", *min_ptr);
}
int main(){
int a[]={1,124,21,4,5,8,3,56,52,0};
int size=sizeof(a)/sizeof(a[0]);
MaxMin(a, size, 0, 0);
}