#include <stdio.h> #include <stdint.h> void find_top_3(uint8_t *arr, uint8_t n) { int a = -1,b=-1,c=-1; for(int idx = 0;idx < n;idx++) { if(arr[idx] > a) { c = b; b = a; a = arr[idx]; } else if(arr[idx] > b) { c = b; b = arr[idx]; } else if(arr[idx] > c) { c = arr[idx]; } } if(n >= 3) printf("%d %d %d",a,b,c); else if(n == 2) printf("%d %d",a,b); else printf("%d",a); // Your logic here } int main() { uint8_t n; scanf("%hhu", &n); uint8_t arr[100]; for (uint8_t i = 0; i < n; i++) { scanf("%hhu", &arr[i]); } find_top_3(arr, n); return 0; }
Test Cases
Test Results
Input
6 10 90 20 80 70 30
Expected Output
90 80 70