Advertisement
Guest User

Untitled

a guest
May 20th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <cstdlib>
  4. #include <ctime>
  5. #include <stdio.h>
  6.  
  7. using namespace System;
  8. using namespace std;
  9.  
  10. short Gen_num()
  11. {
  12. return rand() % 40 + 1;
  13. }
  14.  
  15. short mayor(short *n1, short *n2, short *n3, short *n4)
  16. {
  17. if (*n1 > *n2 && *n1 > *n3 && *n1 > *n4)
  18. {
  19. return *n1;
  20. }
  21. else if (*n2 > *n1 && *n2 > *n3 && *n2 > *n4)
  22. {
  23. return *n2;
  24. }
  25. else if (*n3 > *n1 && *n3 > *n2 && *n3 > *n4)
  26. {
  27. return *n3;
  28. }
  29. else if (*n4 > *n1 && *n4 > *n2 && *n4 > *n3)
  30. {
  31. return *n4;
  32. }
  33. }
  34.  
  35. short menor(short *n1, short *n2, short *n3, short *n4)
  36. {
  37. if (*n1 < *n2 && *n1 < *n3 && *n1 < *n4)
  38. {
  39. return *n1;
  40. }
  41. else if (*n2 < *n1 && *n2 < *n3 && *n2 < *n4)
  42. {
  43. return *n2;
  44. }
  45. else if (*n3 < *n1 && *n3 < *n2 && *n3 < *n4)
  46. {
  47. return *n3;
  48. }
  49. else if (*n4 < *n1 && *n4 < *n2 && *n4 < *n3)
  50. {
  51. return *n4;
  52. }
  53. }
  54.  
  55. short menorMayor(short *n1, short *n2, short *n3, short *n4)
  56. {
  57. short ma = mayor(n1, n2, n3, n4);
  58. short t;
  59. if (ma == *n1)
  60. {
  61. t = mayor(0, n2, n3, n4);
  62. }
  63. else if (ma == *n2)
  64. {
  65. t = mayor(n1, 0, n3, n4);
  66. }
  67. else if (ma == *n3)
  68. {
  69. t = mayor(n1, n2, 0, n4);
  70. }
  71. else if (ma == *n4)
  72. {
  73. t = mayor(n1, n2, n3, 0);
  74. }
  75. return t;
  76. }
  77.  
  78. int main()
  79. {
  80. system("color 7C");
  81. short *n1, *n2, *n3, *n4;
  82. n1 = new short;
  83. n2 = new short;
  84. n3 = new short;
  85. n4 = new short;
  86. srand(time(NULL));
  87. *n1 = Gen_num();
  88. *n2 = Gen_num();
  89. *n3 = Gen_num();
  90. *n4 = Gen_num();
  91.  
  92. cout << *n1 << " " << *n2 << " " << *n3 << " " << *n4 << endl;
  93. cout << mayor(n1, n2, n3, n4) << endl;
  94. cout << menor(n1, n2, n3, n4) << endl;
  95. cout << menorMayor(n1, n2, n3, n4);
  96. _getch();
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement