Question

Please help C++ language Instructions Write a program that prompts the user to enter 50 integers...

Please help C++ language

Instructions 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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
using namespace std;
//driver program
int main()
{
    //declare the array
    int a[50];
    int i,j,k;
    //loop to input the 50 numbers
    for(i=0;i<50;i++)
    {
       cout<<endl<<"Enter Number "<<i+1<<" : ";
       cin>>a[i];
   }
   //display the 50 integers that are entered
   cout<<endl<<"Elements are ";
   for(i=0;i<50;i++)
   cout<<" "<<a[i];
   //loop to find the sum
   //this loop will choose the number for which we want to find the sum of combinations
   for(i=0;i<50;i++)
   {
       //loop to find the addition. It will choose the first number
       for(j=0;j<50;j++)
       {
           if(j!=i) //skip the number for which we want to find the sum
           { //loop to choose the second number of addition
              for(k=j+1;k<50;k++)
       if(k!=i && j!=k) //skip the first number and the number for which we want to find the sum
       {
           if(a[i]==a[j]+a[k]) //osompare the number with the addition of first and second number
           //display the sum combination
       cout<<endl<<a[i]<<" = "<<a[j] <<" + "<<a[k];
                   }
           }
       }
   }
}

OUTPUT

NOTE: FOR EASY CONVENIENCE FOR FINDING OUTPUT I HAVE CHANGE THE NUMBERS FROM 50 TO 10 AND TAKE THE SNAPSHOT.

Add a comment
Know the answer?
Add Answer to:
Please help C++ language Instructions Write a program that prompts the user to enter 50 integers...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Program in C language for: 1. Create a C program to read 7 integers...

    Write a Program in C language for: 1. Create a C program to read 7 integers and store them in an array. Next, the program is to check if the array is symmetric, that is if the first element is equal to the last one, the value of the second one is equal to the value of the last but one, and so on. Since the middle element is not compared with another element, this would not affect the symmetry...

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • In Java - Write a program that prompts the user to enter two integers and displays...

    In Java - Write a program that prompts the user to enter two integers and displays their sum. If the input is incorrect, prompt the user again. This means that you will have a try-catch inside a loop.

  • Write java program that prompts the user to enter integers from the keyboard one at a...

    Write java program that prompts the user to enter integers from the keyboard one at a time. Program stops reading integers once the user enters the same value three times consecutively. Program then outputs "Same entered 3 in a row. "

  • Please solve this C language progrm (2-D Array program) the most basic way ! Thank You!...

    Please solve this C language progrm (2-D Array program) the most basic way ! Thank You! Write a function that takes a 4 x 4 array of integers as its parameter. The function must use two nested for-loops to determine the largest integer in the array as well as its row and column numbers. Recall that C-functions cannot return multiple values. Use pointers in the function parameter list to relay the results to the caller program. Write another function, which...

  • Java: Write a program that prompts the user to enter integers in the range 1 to...

    Java: Write a program that prompts the user to enter integers in the range 1 to 50 and counts the occurrences of each integer. The program should also prompt the user for the number of integers that will be entered. As an example, if the user enters 10 integers (10, 20, 10, 30, 40, 49, 20, 10, 25, 10), the program output would be: 10 occurs 4 times 20 occurs 2 times 25 occurs 1 time 30 occurs 1 time...

  • Python Code Write a program using functions and mainline logic which prompts the user to enter...

    Python Code Write a program using functions and mainline logic which prompts the user to enter a number. The number must be at least 5 and at most 20. (In other words, between 5 and 20, inclusive.) The program then generates that number of random integers and stores them in a list. The random integers should range from 0 to 100. (You can use a wider range if you want, but the lower end of the range must be at...

  • IN C language Write a C program that prompts the user to enter a line of...

    IN C language Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr andcreadLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate...

  • Write a C program that prompts the user to enter a series of integers that represent...

    Write a C program that prompts the user to enter a series of integers that represent a coded message. I have given you the decoder program so that you can see how it is written using array notation. Your assignment is to convert the code to a program that uses only pointers and pointer math. Your program must use pointer notation and pointer math (i.e. no array index notation other than in the declaration section, no arrays of pointers and...

  • Please solve this question using c++ language Problem 2. More Probleml. The program builds the array...

    Please solve this question using c++ language Problem 2. More Probleml. The program builds the array of integers that contains duplicates as well. Your program should find the sum of all unique elements in the array using a function findUniqueSum Arrays Write a program that as before asks the user to enter input as in оn Sample Input/Output Enter a list of numbers ending with -999 3 1 4 55-999 The sum of unique numbers is: 13 Enter a list...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT