# 13591 - Second Highest Value >author: Utin ###### tags: `math` --- ## Brief See the code below ## Solution 0 ```c= #include<stdio.h> int arr[1000001]; int main() { int n, temp[2]; scanf("%d", &n); for(int i=0; i<n; i++) { scanf("%d", &arr[i]); } for(int i=0; i<n; i++) { if(i == 0) { temp[0] = arr[i]; temp[1] = arr[i]; printf("%d", 0); } else if(i == 1) { if(arr[i] > arr[i-1]) temp[1] = arr[i]; else temp[0] = arr[i]; printf("%d", temp[0]); } else { if(arr[i] > temp[1]) { temp[0] = temp[1]; temp[1] = arr[i]; } else if(arr[i]>temp[0] && arr[i]<temp[1]) { temp[0] = arr[i]; } printf("%d", temp[0]); } if(i != n-1) printf(" "); else printf("\n"); } } // By Utin ``` ## Reference
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up