Tuesday, February 10, 2015

Second smallest value in an array

/* Find the second smallest value in an array */ #include<stdio.h> int main() { int a[50], size, i, j=0, s, ss; 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]); s = a[0]; ss = a[0]; for (i=0; i<size; i++) { if (s > a[i]) { ss = s; s = a[i]; } } printf("Second smallest: %d", ss); getch(); return 0; }

Share

& Comment

0 comments:

Post a Comment

 

Copyright © 2015 Code Fervor™ is a registered trademark.

Designed by Templateism By Naman Kumar