//Program to find Second MIN element in Array #include<stdio.h> #include<conio.h> void main () { int array[100], min, sMin, i, num; clrscr (); printf ( "Enter Size of Array(2 to 100):" ); scanf ( "%d" ,&num); printf ( "Enter Elements of Array: " ); for (i=0; i<num; i++) scanf ( "%d" ,&array[i]); //initialize MIN with first element of array min = array[0]; sMin = 0; for (i=1; i<num; i++) { if (min > array[i]) { sMin = min; min = array[i]; } else if (sMin ==0 || sMin > array[i]) sMin = array[i]; } printf ( "Second Min element in array : %d" ,sMin); getch (); } |
Output:
Enter Size of Array(up to 100):5
Enter Elements of Array:45
67 21 87 56 Second Min element in array :56
No comments:
Post a Comment