Skip to content

Commit e67957f

Browse files
committed
Find my min solved
1 parent 526a2e9 commit e67957f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/lab3_task1.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323

2424
#include <stdio.h>
25+
#include <limits.h>
2526

2627
// Function prototypes
2728
int array_min(int arr[], int size);
@@ -44,7 +45,13 @@ int main(void) {
4445
// Implement functions below
4546
int array_min(int arr[], int size) {
4647
// TODO: return smallest element
47-
return 0; // placeholder
48+
int my_min = INT_MAX; //set to max infinity
49+
for (int i=0;i<size;i++) {
50+
if (my_min > arr[i]) {
51+
my_min = arr[i];
52+
}
53+
}
54+
return my_min; // placeholder
4855
}
4956

5057
int array_max(int arr[], int size) {

0 commit comments

Comments
 (0)