Question
Instructions Redo Programming Exercise 14 by first sorting the array before determining the array elements that are the sum of two other elements. Use a
Instructions
Redo Programming Exercise 14 by first sorting the array before determining the array elements that are the sum of two other elements. Use a selection sort algorithm, discussed in this chapter to sort the array.
Instructions and code for Programming Exercise 14 have been included for your convenience.
Exercise 14
Write a program that prompts the user to enter 50 integers and stores them in an array. The program then determines and outputs which numbers in the array are the sum of two other array elements. If an array element is the sum of two other array elements, then for this array element, the program should output all such pairs.
/* 10 17 23 65 34 6 18 27 35 110 75 25 100 24 19 67 45 88 70 96 41 36 72 150 125 25 77 200 90 166 139 55 31 8 29 119 126 137 34 62 135 121 108 197 45 35 24 1 16 43 */ #include
using namespace std;
const int LIST_SIZE = 50;
int main() { int list[50];
cout << "Enter " << LIST_SIZE << " integers: "; for (int i = 0; i < LIST_SIZE; i++) cin >> list[i]; cout << endl;
for (int i = 0; i < LIST_SIZE; i++) { cout << "list[" << i << "] = " << list[i] << " is the sum of: "; for (int j = 0; j < LIST_SIZE; j++) for (int k = j + 1; k < LIST_SIZE; k++) if (list[i] == list[j] + list[k]) cout << "list[" << j << "], list[" << k << "]; "; cout << endl; cout << "----------------------" << endl;; }
return 0; }
Please post the text, not images.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started