First Largest Element and Second Largest Element in an Array.
Procedure:
#include <stdio.h> int main() { int arra[500], number, i; int FirstMax, SecondMax; printf("Enter Number of Elements in array\n"); scanf("%d", &number); printf("Enter %d numbers \n", number); for(i = 0; i < number; i++){ scanf("%d", &arra[i]); } FirstMax = SecondMax = -1; for(i = 0; i < number; i++){ if(arra[i] > FirstMax){ SecondMax = FirstMax; FirstMax = arra[i]; } else if (arra[i] > SecondMax && arra[i] < FirstMax){ SecondMax = arra[i]; } } printf("First Largest Element : %d \nSecond Largest Element: %d", FirstMax, SecondMax); return 0; }
Output: