Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. int main()
  6. {
  7. char n = 0, max[] = { 0, 0, 0 };
  8. printf("Enter 3 or more\n");
  9. scanf("%d", &n);
  10. int a = 0;
  11. if (n < 3)
  12. {
  13. printf("Restart the program and enter 3 or more\n");
  14. return 0;
  15. }
  16. for (int i = 0; i < 3; ++i)
  17. {
  18. scanf("%d", &a);
  19. max[i] = a;
  20. }
  21.  
  22. for (int j = 0; j < 2; ++j)
  23. {
  24. for (int i = 0; i < 2; ++i)
  25. {
  26. if (max[i] > max[i + 1])
  27. {
  28. int b = max[i + 1];
  29. max[i + 1] = max[i];
  30. max[i] = b;
  31. }
  32. }
  33. }
  34.  
  35. if (n > 3)
  36. {
  37. for (int i = 3,k = 0; i < n; ++i)
  38. {
  39. scanf("%d", &a);
  40.  
  41. if (a > max[0])
  42. {
  43. ++k;
  44. if (a > max[1])
  45. {
  46. ++k;
  47. if (a > max[2])
  48. {
  49. ++k;
  50. }
  51. }
  52. }
  53. printf("%d ", k);
  54.  
  55. if (k == 3)
  56. {
  57. max[0] = max[1];
  58. max[1] = max[2];
  59. max[2] = a;
  60.  
  61. }
  62. if (k == 2)
  63. {
  64. max[0] = max[1];
  65. max[1] = a;
  66. }
  67. if (k == 1)
  68. {
  69. max[0] = a;
  70. }
  71.  
  72. k = 0;
  73. }
  74. }
  75. printf("\n");
  76. for (int i = 2; i > -1; --i)
  77. {
  78. printf("%d ",max[i]);
  79. }
  80. printf("\n");
  81. getchar();
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement