/* Find the second largest value in an unsorted array */
#include <stdio.h>
int main() {
int a[50], size, i, j=0, l, sl;
printf("Enter the size of the array: ");
scanf("%d", &size);
printf("Enter %d elements in to the array: ", size);
for(i=0; i<size; i++)
scanf("%d", &a[i]);
l = a[0];
sl = a[0];
for (i=0; i<size; i++) {
if (l < a[i]) {
sl = l;
l = a[i];
}
}
printf("Second largest: %d", sl);
getch();
return 0;
}
Tuesday, February 10, 2015
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment