Program to find Second largest number in an array in c
- #include"stdio.h"
- main()
- {
- int a[]={15,67,25,90,40};
- int k;
- k=large_number(a);
- printf("%d ",k);
- }
- int large_number(int un[5])
- {
- int big1,big2;
- int i;
- big1 = un[0];
- for ( i=1;i<5 font="" i="">5>
- if ( big1 < un[i] )
- big1 = un[i];
- if ( big1!=un[0] )
- big2=un[0];
- else
- big2=un[1];
- for(i=1; i<5 font="" i="">5>
- if (big1!=un[i] && big2 < un[i] )
- big2=un[i];
- return big2;
- }
No comments
Post a Comment