fork download
  1. #include <stdio.h>
  2. #include <limits.h>
  3. // PROGRAM TO FIND SECOND MAXIMUM NO. IN AN ARRAY USING ONLY ONE LOOP
  4. int main(void) {
  5. int arr[8]={10,7,8,19,19,6,7,8};
  6. int max=INT_MIN;
  7. int smax=INT_MIN;
  8.  
  9. for(int i=0;i<8;i++){
  10. if(max<arr[i]){
  11. smax=max;
  12. max=arr[i];
  13. }
  14. else if(smax<arr[i] && arr[i]!=max){
  15. smax=arr[i];
  16. }
  17. }
  18. printf("Second maximum no. is %d",smax);
  19. return 0;
  20. }
  21.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Second maximum no. is 10