My issue
what’s wrong with my code? I’ve run it in vs code and I got the correct output.
My code
#include<stdio.h>
int main()
{
int t, n, firstLargest, secondLargest;
scanf("%d", &t);
while(t > 0)
{
scanf("%d", &n);
int a[n];
for(int i = 0; i < n; i++)
scanf("%d", &a[i]);
firstLargest = a[0];
secondLargest = a[0];
for(int i = 1; i < n; i++)
{
if(a[i] > firstLargest)
{
secondLargest = firstLargest;
firstLargest = a[i];
}
else if(a[i] < firstLargest && a[i] > secondLargest)
{
secondLargest = a[i];
}
}
printf("%d\n", firstLargest + secondLargest);
t--;
}
return 0;
}
Learning course: Arrays using C
Problem Link: Largest and Second Largest Practice Problem in - CodeChef
