Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- char n = 0, max[] = { 0, 0, 0 };
- printf("Enter 3 or more\n");
- scanf("%d", &n);
- int a = 0;
- if (n < 3)
- {
- printf("Restart the program and enter 3 or more\n");
- return 0;
- }
- for (int i = 0; i < 3; ++i)
- {
- scanf("%d", &a);
- max[i] = a;
- }
- for (int j = 0; j < 2; ++j)
- {
- for (int i = 0; i < 2; ++i)
- {
- if (max[i] > max[i + 1])
- {
- int b = max[i + 1];
- max[i + 1] = max[i];
- max[i] = b;
- }
- }
- }
- if (n > 3)
- {
- for (int i = 3,k = 0; i < n; ++i)
- {
- scanf("%d", &a);
- if (a > max[0])
- {
- ++k;
- if (a > max[1])
- {
- ++k;
- if (a > max[2])
- {
- ++k;
- }
- }
- }
- printf("%d ", k);
- if (k == 3)
- {
- max[0] = max[1];
- max[1] = max[2];
- max[2] = a;
- }
- if (k == 2)
- {
- max[0] = max[1];
- max[1] = a;
- }
- if (k == 1)
- {
- max[0] = a;
- }
- k = 0;
- }
- }
- printf("\n");
- for (int i = 2; i > -1; --i)
- {
- printf("%d ",max[i]);
- }
- printf("\n");
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement