In: Computer Science
Write a program that first asks the user to input 10 different integers a_1-a_10 and another integer b, then outputs all the pairs of the integers a_i and a_j satisfying a_i+a_j=b, i!=j. If there is no such pair, output “not found.”
Since you haven't mentioned any particular programming language here is the code of the given program in c++ :-
#include <iostream>
using namespace std;
int main()
{
int arr[10]; //array to store ten different integers
cout<<"Enter ten different integers:\n";
for(int i=0;i<10;i++){
cin>>arr[i];
}
int b;
cout<<"Enter another number:\n ";
cin>>b;
int count=0; // to count number of pairs whose sum is equal to
given integer
for (int i=0; i<10; i++) { //LOOP TO FIND PAIR OF INTEGERS WHOSE
SUM IS EQUAL TO GIVEN INTEGER
for (int j=i+1; j<10; j++) {
if (arr[i]+arr[j] == b) {
count++;
cout<<" "<<arr[i]<<"
"<<arr[j]<<endl;
}
}
}
if(count==0){ // when no pair are there whose sum is equal to sum
of given integer
cout<<"Not found\n";
}
return 0;
}
SCREENSHOT OF PROGRAM:-
SAMPLE OUTPUTS:-
If you have any query feel free to ask in comment.
HAPPY LEARNING!