what is second largest value, like we have 5 number of a series 12,45,78,15,23. in this series 78 is the first largest value, 45 is the second largest value, and 23 is the third largest value so on.
Program
#include <stdio.h> #include <limits.h> int main() { int N = 0, fMax, ScMax, num; fMax = ScMax = INT_MIN; printf('Enter the value: '); scanf('%d',&N); for(int i = 1; i<=N; i++){ printf('Enter the %d value: ', i); scanf('%d',&num); // Condition for finding the second largest value if(num>fMax) { ScMax = fMax; fMax = num; } else if(num<fMax && num>ScMax) ScMax = num; } printf('\nFirst largest value : %d\n',fMax); printf('Second largest value : %d',ScMax); return 0; }
Output:
Enter the value: 5
Enter the 1 value: 45
Enter the 2 value: 28
Enter the 3 value: 96
Enter the 4 value: 0
Enter the 5 value: 12
First largest value : 96
Second largest value : 45
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
First of all,
what is second largest value, like we have 5 number of a series 12,45,78,15,23. in this series 78 is the first largest value, 45 is the second largest value, and 23 is the third largest value so on.
Program
Output: