C Program to find Second largest Number in an Array
C Programming Language Array in C Language (Article) Array in C Language (Program)
1063Program:
/* C Program to find Second largest Number in an Array */ #include #include int main() { int arr[50], i, Size; int first, second; printf("\n Please Enter the Number of elements in an array : "); scanf("%d", &Size); printf("\n Please Enter %d elements of an Array \n", Size); for (i = 0; i < Size; i++) { scanf("%d", &arr[i]); } first = second = INT_MIN; for (i = 0; i < Size; i++) { if(arr[i] > first) { second = first; first = arr[i]; } else if(arr[i] > second && arr[i] < first) { second = arr[i]; } } printf("\n The Largest Number in this Array = %d", first); printf("\n The Second Largest Number in this Array = %d\n", second); return 0; }
Output:
Please Enter the Number of elements in an array : 5 Please Enter 5 elements of an Array 10 90 80 90 80 The Largest Number in this Array = 90 The Second Largest Number in this Array = 80 Press any key to continue . . .
Explanation:
Nope
This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.