Contact Learn C
Copy Program Share Program

Program 344 : Array Pair which when added will give nearest zero

Program 344 : Array Pair which when added will give nearest zero
 
#include<stdio.h>
#include<stdlib.h>
main()
{
 int i,j,a[100],size,minSum=0,minFirst,minSecond,sum=0;
 printf("Enter Size of array\n");
 scanf("%d",&size);
 for(i=0;i<size;i++)
 scanf("%d",&a[i]);
 minSum=a[0]+a[1];
 for(i=0;i<size;i++)
 {
  for(j=i+1;j<size;j++){
   sum=a[i]+a[j];
      if(abs(minSum)>abs(sum))
      {
       minSum=sum;
        minFirst=i;
       minSecond=j;
      }
  }
  
 }
 printf("Sum of %d,%d gives nearest 0\n",a[minFirst],a[minSecond]);
 
}
Explanation:
//Coming Soon

Output: 

Array Pair which when added will give nearest zero





 

Download App and Learn when ever you want

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