ridwan100

second largest

Nov 4th, 2023
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4.     int nums[5] = {5,4,3,2,4};
  5.     int max = nums[0];
  6.     int smax = nums[1];
  7.     for(int i = 0;i<5;i++){
  8.        
  9.         if(nums[i]>max){
  10.             smax = max;
  11.             max = nums[i];
  12.            
  13.         }
  14.         else{
  15.             if(nums[i]<max && nums[i]>smax){
  16.                 smax = nums[i];
  17.             }
  18.         }
  19.     }
  20.     cout<<smax<<endl;
  21. }
Add Comment
Please, Sign In to add comment