TheFestFever.com

Our aim is to connect students from campuses all over Delhi by making them aware of all Technical, Cultural, Management fests, workshops, Seminars organized by every college in Delhi.

Join Us Now

Program 12: Write a C++ program to get the indices of two numbers such that sum of those numbers is equal to the specific target.

#include<iostream>
#include<stdlib.h>
using namespace std;

int main()
{
	int arr[10],target;
	cout<<"\nenter the elements of an array : ";
	for(int i=0;i<10;i++)
	{
		cin>>arr[i];
	}

	cout<<"\nenter the target : ";
	cin>>target;
	for(int i=0;i<9;i++)
	{
		for(int j=i+1;j<10;j++)
		{
			if((arr[i]+arr[j])==target)
			{
				cout<<"\n\nAppropriate Indices are "<<i<<" & "<<j;
				cout<<"\nAnd the values are "<<arr[i]<<" & "<<arr[j];
			}
		}
	}
	cout<<"\ngiven target is not possible!!!";
	return 0;
}



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.