Given an 2d array a[][] and a number b, check for pair in a[][] with sum as b

 2d array :-Given an 2d array a[][] and a number b, check for pair in a[][] with sum as b
Write a C program that, given an array a[][] of n numbers and another number b, determines whether or not there exist two elements in a[][] whose sum is exactly b 

#include<stdio.h>

main()
{

 int a[20][20],row,col,b,s,i,j,k=0,add[20];;

  printf("Enter Number b:\n");
  scanf("%d",&b);

  printf("Enter Nuber of Row:\n");
  scanf("%d",&row);

  printf("Enter Nuber of Col:\n");
  scanf("%d",&col);

  printf("Read Array Element From User:");

  for(i=0;i<row;i++)
    {
     for(j=0;j<col;j++)
       {
      scanf("%d",&a[i][j]);
       }
    }

   for(i=0;i<row;i++)
     {
      for(j=0;j<col;j++)
       {
         add[k]=a[i][j];
         k++;
       }
     }

   for(i=0;i<k-2;i++)
     {
      for(j=i+1;j<k-1;j++)
       {
         s=add[i]+add[j];
         if(s==b)
         printf("Sum of Pair add[%d] & add[%d] equal to b=%d\n",i,j,b);
       
       }
   
     }
 
}
Copyright © C Program | Java | OpenGL Programming | Hadoop at Computaholics