Problem Description
A bag contains set of integers and it is discovered by Ram. There is sheet in that bag. The person who found the bag should find the second largest number from the set of numbers. If the rightly found the will get a gold.. If you wish get the prize you can also try...Test Case 1
Input (stdin)5 5 3 1 2 6
Expected Output5
Test Case 2
Input (stdin)6 16 58 2 1 6 99
Expected Output58
Program
#include <stdio.h> int main() { int a[50],size,i,j=0,big,secondbig; scanf("%d",&size); for(i=0;i<size;i++) scanf("%d",&a[i]); big=a[0]; for(i=1;i<size;i++) { if(big<a[i]) { big=a[i]; j=i; } } secondbig=a[size-j-1]; for(i=1;i<size;i++) { if(secondbig<a[i]&&j!=i) secondbig=a[i]; } printf("%d",secondbig); return 0; }
No comments:
Post a Comment
Note: only a member of this blog may post a comment.