fork download
  1. #include <stdio.h>
  2. #include <limits.h>
  3.  
  4. #define MAX_SIZE 1000
  5. int main()
  6. {
  7. int arr[MAX_SIZE],size,i;
  8. int max1, max2;
  9. printf("Enter size of the array (1-1000): 100");
  10. scanf(" %d", &size);
  11. printf("Enter elements in the array:9");
  12. for(i=0; i<size; i++)
  13. {
  14. scanf("%d",&arr[i]);
  15. }
  16. max1 = max2 =INT_MIN;
  17. for(i=0; i<size; i++)
  18. {
  19. if(arr[i]>max1)
  20. {
  21. max2=max1;
  22. max1=arr[i];
  23. }
  24. else if(arr[i]>max2 && arr[i] < max1)
  25. {
  26. max2=arr[i];
  27. }
  28. }
  29. printf(" First largest =%d\n",max1);
  30. printf("Second largest =%d", max2);
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
Enter size of the array (1-1000): 100Enter elements in the array:9 First largest =-2147483648
Second largest =-2147483648