Write a program to find the second largest number in the given array of numbers.

This answer is restricted. Please login to view the answer of this question.

Login Now
#include <stdio.h>
void main()
{
    int i, j, a, n, counter, ave, number[30];

    printf("Enter the value of N: ");
    scanf("%d", &n);

    printf("Enter the numbers:\n");
    for (i = 0; i < n; ++i)
        scanf("%d", &number[i]);
        
    for (i = 0; i < n; ++i)
    {
        for (j = i + 1; j < n; ++j)
        {
            if (number[i] < number[j])
            {
                a = number[i];
                number[i] = number[j];
                number[j] = a;
            }
        }
    }
    
    printf("The 2nd largest number is = %d\n", number[1]);
}

The output of the above program is

Enter the value of N: 5
Enter the numbers:
1
3
10
8
9
The 2nd largest number is = 9
If you found any type of error on the answer then please mention on the comment or report an answer or submit your new answer.
Leave your Answer:

Click here to submit your answer.

Discussion
0 Comments
  Loading . . .