Breaking News

Program to find Second largest number in an array in c


  1. #include"stdio.h"
  2. main()
  3. {
  4. int a[]={15,67,25,90,40};
  5. int k;
  6. k=large_number(a);
  7. printf("%d ",k);
  8. }
  9. int large_number(int un[5])
  10. {
  11. int big1,big2;
  12. int i;
  13. big1 = un[0];
  14. for ( i=1;i<5 font="" i="">
  15. if ( big1 < un[i] )
  16. big1 = un[i];
  17. if ( big1!=un[0] )
  18. big2=un[0];
  19. else
  20. big2=un[1];
  21. for(i=1; i<5 font="" i="">
  22. if (big1!=un[i] && big2 < un[i] )
  23. big2=un[i];
  24. return big2;
  25. }

No comments