Skip to content

Commit 301352a

Browse files
Add iterative min and max in C
1 parent be89a96 commit 301352a

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1053,8 +1053,8 @@ In order to achieve greater coverage and encourage more people to contribute to
10531053
<tr>
10541054
<td>Iterative Min and Max</td>
10551055
<td> <!-- C -->
1056-
<a href="./CONTRIBUTING.md">
1057-
<img align="center" height="25" src="./logos/github.svg" />
1056+
<a href="./src/c/IterativeMinAndMax.c">
1057+
<img align="center" height="25" src="./logos/c.svg" />
10581058
</a>
10591059
</td>
10601060
<td> <!-- C++ -->

src/c/IterativeMinAndMax.c

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
int array[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
5+
6+
int min = array[0];
7+
int max = array[0];
8+
9+
for (int i = 1; i < 8; ++i) {
10+
if (array[i] < min) {
11+
min = array[i];
12+
}
13+
if (array[i] > max) {
14+
max = array[i];
15+
}
16+
}
17+
18+
printf("min: %d\n", min);
19+
printf("max: %d\n", max);
20+
return 0;
21+
}

0 commit comments

Comments
 (0)