C program to find two smallest elements in a one dimensional array
Write a C program to find two smallest elements in a one dimensional array.
Example: Type1: (all the elements are not same & no of element is more than two)
Array size: 4
Elements: 32 54 -6 43
Output: -6 32
Example: Type2: (second minimum doesn’t exist as size of array < 2)
Array size : 1
Elements: 4
Output: 4
Example: Type3: (all elements are same, thus only one smallest element)
Array size : 4
Elements: 13 13 13 13
Output: 13
Algorithm:
Only one smallest value exists, print it
Else
Print min & sec_min
C implementation to find two smallest elements in a one dimensional array
Output (Type1 example)
Output (Type2 example)
Output (Type3 example)
need an explanation for this answer? contact us directly to get an explanation for this answer