199: Find the number of pairs of integers in a given array of integers whose sum is equal to a specified number
// Find the number of pairs of integers in a given array of integers whose sum is equal to a specified number
#include <iostream>
using namespace std;
int main()
{
int size;
cout << "Enter the size of array: ";
cin >> size;
int array[size];
for (int i = 0; i < size; i++)
{
cout << "Enter a string for index " << i << ": ";
cin >> array[i];
}
int num;
cout << "Enter a number: ";
cin >> num;
system("cls");
cout << "Array elements pair whose sum = " << num << ':';
for (int i = 0; i < size; i++)
{
for (int j = i + 1; j < size; j++)
{
if (array[i] + array[j] == num)
{
cout << endl << array[i] << ' ' << array[j];
}
}
}
return 0;
}
Comments
Post a Comment