1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
mars1129 [50]
4 years ago
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 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.
Computers and Technology
1 answer:
Marrrta [24]4 years ago
5 0

Answer:

Here is code in C++.

#include <bits/stdc++.h>

using namespace std;

int main()

{  

int n=50;

   // integer array to store 50 integers

   int arr[n];

   cout << "Enter 50 integers: ";

   //read 50 integers into array

   for (int i = 0; i < n; i++)

       cin >> arr[i];

   cout << endl;

   

   //sort the array

   sort(arr,arr+n);

   

   // find all the pairs which give sum equal to any element of the array

   for (int i = 0; i < n; i++)

   {

       cout<<"pair which give sum equal to  ";

       cout << arr[i] <<" is :";

       for (int j = 0; j < n; j++)

           for (int k = j + 1; k < n; k++)

               if (arr[i] == arr[j] + arr[k])

                   cout <<"("<<arr[j]<<" & "<< arr[k] <<")"<<",";

       cout << endl;

       cout << "*******************************" << endl;;

   }

   return 0;

}

Explanation:

Read 50 integers into an array from user.Sort the array in ascending order.Travers the sorted array and find all pairs which give sum of equal to any element of the array.Then print all such pairs.

Output:

Enter 50 integers: 23 30 34 1 3 4 9 12 96 92 80 84 123 54 67 87 34 55 21 38 29 111 10 44 103 47 83 72 77 88 80 56 49 5 102 166 134 200 205 188 178 133 154 148 162 191 193 207 209 44                                                                                                                                                                    

 pair which give sum equal to  1 is :                                                *******************************

pair which give sum equal to  3 is :                                                     *******************************    

pair which give sum equal to  4 is :(1 & 3),                                         ******************************    

pair which give sum equal to  5 is :(1 & 4),                                         ******************************    

pair which give sum equal to  9 is :(4 & 5),                                         *******************************  

pair which give sum equal to  10 is :(1 & 9),                                       *******************************  

pair which give sum equal to  12 is :(3 & 9),                                       *******************************  

pair which give sum equal to  21 is :(9 & 12),                                      *******************************  

pair which give sum equal to  23 is :                                                    *******************************    

pair which give sum equal to  29 is :                                                    *******************************    

pair which give sum equal to  30 is :(1 & 29),(9 & 21),                        *******************************  

pair which give sum equal to  34 is :(4 & 30),(5 & 29),                     *******************************    

pair which give sum equal to  34 is :(4 & 30),(5 & 29),                     *******************************    

pair which give sum equal to  38 is :(4 & 34),(4 & 34),(9 & 29),  

.

.

.

.

  

You might be interested in
Who would use a magnetic hard drive? Give a scenario and include examples as well as detail.
dybincka [34]
A magnetic hard drive well all hardrives have a magnet n them id say if it was to withstand heat so it whould stay on the magnet therefore not compromising the data <span />
3 0
4 years ago
Which principle or element of layout design is highlighted in this event poster?
Oduvanchick [21]

The  principle or element of layout design is highlighted in an event poster in option i: The headline.

<h3>What are the elements of page layout?</h3>

The poster is known to be one that often uses a kind of hierarchy and centered text alignment as its element.

Note that it is one whose Lines of use is said to be made up of different kinds of type styles, sizes and others.

The simple elements of an advertising poster is made up of:

1. The headline.

2. The sub-head.

3. The body copy.

4. The caption.

The elements of page layout are visual hierarchy, visual flow, and others. Hence, the  principle or element of layout design is highlighted in an event poster in option i: The headline.

Learn more about layout design from

brainly.com/question/2501083

#SPJ1

6 0
2 years ago
What features are provided by most GUIs?
PSYCHO15rus [73]

Windows is the answer

8 0
4 years ago
What is the purpose of a project overview?
andreyandreev [35.5K]

Answer:

option 3 should be the answer is this helps please give the brainliest award.

7 0
3 years ago
Read 2 more answers
Which form of data does the image represent? (10 points)<br><br> A. Analog data<br> B. Digital data
dusya [7]
Where is the image?, I cant answer if there is no image
6 0
3 years ago
Read 2 more answers
Other questions:
  • Can you recover deleted bookmarks on a Chromebook? If so, how?
    5·2 answers
  • Which formal security-related process should take place at the beginning of the code creation project? Group of answer choices R
    13·1 answer
  • Ophelia is entering a Get Fit! sporting goods store in a shopping mall when her heel gets caught in a heating grate at the thres
    9·1 answer
  • ASAP ε=ε=ᕕ(°□°)ᕗ<br> Sorry if you can't see it but please help me if you can!
    6·1 answer
  • The write-ahead logging (WAL) protocol simply means that Select one: a. the log record for an operation should be written before
    7·1 answer
  • What is the available vector for each resource and the need matrix for each thread. Note that an available vector depicts the qu
    11·1 answer
  • Five advantages of Internet​
    6·2 answers
  • The programming interface for a legacy motor controller accepts commands as binary strings of variable lengths.
    15·1 answer
  • enter formula that uses the IF function to test whether the number of years of experience (cell M5) is greater than or equal to
    9·1 answer
  • What are the different elements of a window?​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!