C Program to Find Smallest Element in Array in C Programming
Program : Find Smallest Element in Array in C Programming
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 | #include<stdio.h> int main() { int a[30], i, num, smallest; printf("\nEnter no of elements :"); scanf("%d", &num); //Read n elements in an array for (i = 0; i < num; i++) scanf("%d", &a[i]); //Consider first element as smallest smallest = a[0]; for (i = 0; i < num; i++) { if (a[i] < smallest) { smallest = a[i]; } } // Print out the Result printf("\nSmallest Element : %d", smallest); return (0); } |
Output :
1 2 3 | Enter no of elements : 5 11 44 22 55 99 Smallest Element : 11 |