Contact Learn C
Copy Program Share Program

Program 249: Program to display Array Pairs whose Sum is equal to a Number

Program 249: Program which displays Array Pairs whose Sum is equal to a Number

#include<stdio.h>
main()
{
 int i,j,k,n,add,flag=0;
 printf("Enter number of elements in array\n");
 scanf("%d",&n);
 int a[n];
 printf("Enter an added number for which you want distinct pairs from an array\n");
 scanf("%d",&add);
 printf("Enter Elements of arrays\n");
 for(i=0;i<n;i++)
 {
  scanf("%d",&a[i]);
 }
 printf("Array elements which when added gives %d\n",add);
 for(i=0;i<n;i++)
 {
  for(j=i+1;j<n;j++)
  {
   if((a[i]+a[j])==add)
   {
    flag=1;
    printf("(%d,%d) found at [%d,%d]\n",a[i],a[j],i+1,j+1);
   }
  }
 }
 if(flag==0)
 {
  printf("Not Found\n");
 }
 printf("\n");
}
Explanation:

//Coming Soon

Output:

Program to display Array Pairs whose Sum is equal to a Number

Program to display Array Pairs whose Sum is equal to a Number Output



Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide