Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

second largest number in array

public static void SecondndLargestfromarray()
{
    var scan = new Scanner(System.in);
    var n = scan.nextInt();
    long l=Long.MIN_VALUE;
    long p=Long.MIN_VALUE;

    for (int i = 0; i < n; i++) {
        var sc = scan.nextLong();
        if(sc>l)
        {
            p=l;
            l=sc;
        }
        else if(sc>p ) p = sc;
    }
    System.out.println(p);
}
 
PREVIOUS NEXT
Tagged: #largest #number #array
ADD COMMENT
Topic
Name
3+4 =