Skip to content

Commit ccd16cd

Browse files
Merge pull request seeditsolution#53 from devu2000/patch-1
code for smallest number in an array added.
2 parents 39e8aef + 7c9fffb commit ccd16cd

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Smallest number in an array

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include<stdio.h>
2+
3+
int main() {
4+
int a[30], i, num, smallest;
5+
6+
printf("\nEnter no of elements :");
7+
scanf("%d", &num);
8+
9+
//Read n elements in an array
10+
for (i = 0; i < num; i++)
11+
scanf("%d", &a[i]);
12+
13+
//Consider first element as smallest
14+
smallest = a[0];
15+
16+
for (i = 0; i < num; i++) {
17+
if (a[i] < smallest) {
18+
smallest = a[i];
19+
}
20+
}
21+
22+
// Print out the Result
23+
printf("\nSmallest Element : %d", smallest);
24+
25+
return (0);
26+
}

0 commit comments

Comments
 (0)