Tuesday, February 10, 2015

Second largest value in an unsorted array

/* 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; }

Share

& Comment

0 comments:

Post a Comment

 

Copyright © 2015 Code Fervor™ is a registered trademark.

Designed by Templateism By Naman Kumar