Skip to content

Commit c177d4b

Browse files
Add files via upload
1 parent d09606c commit c177d4b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Program to find the smallest element from an array.
2+
3+
#include <stdio.h>
4+
5+
int main() {
6+
7+
// create an integer array of size 5
8+
int numbers[5];
9+
10+
// get input value for the array
11+
for (int i = 0; i < 5; i++) {
12+
scanf("%d", &numbers[i]);
13+
}
14+
15+
// create a variable smallest and assign first element of numbers to it
16+
int smallest = numbers[0];
17+
18+
// run a for loop from i = 1 to i < 5
19+
// check if smallest is less than element at i
20+
for (int i = 1; i < 5; i++) {
21+
if (numbers[i] < smallest) {
22+
smallest = numbers[i];
23+
}
24+
}
25+
26+
// print smallest
27+
printf("%d", smallest);
28+
29+
return 0;
30+
}

0 commit comments

Comments
 (0)