Advertisement
2001paskalpaskalev

podgotvitelna-zada4a-1

Jan 17th, 2024
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. const int sizeA = 10;
  4. const int sizeB = 3;
  5.  
  6. int getHighest(int x[]) {
  7. int result = 0;
  8. for (int i = 0; i < sizeB; i++)
  9. {
  10. if (x[i] >= result) {
  11. result = x[i];
  12. }
  13. }
  14. return result;
  15. }
  16.  
  17. int getLowest(int x[]) {
  18. int result = 999;
  19. for (int i = 0; i < sizeB; i++)
  20. {
  21. if (x[i] <= result) {
  22. result = x[i];
  23. }
  24. }
  25. return result;
  26. }
  27.  
  28. int multSum(int a[], int b[]) {
  29. int lowest = getLowest(b);
  30. int highest = getHighest(b);
  31.  
  32. int acc = 0;
  33.  
  34. for (int i = 0; i < sizeA; i++)
  35. {
  36. if (a[i] <= highest && a[i] >= lowest) {
  37. acc += a[i];
  38. }
  39. }
  40. return acc;
  41. }
  42.  
  43. int main()
  44. {
  45. int set1[] = { 5, 2, 3, 8, 1, 6, 4, 12, 9, 10 };
  46. int set2[] = { 6, 9, 4 };
  47.  
  48. cout << multSum(set1, set2);
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement