Computer Science, asked by pavanpardeep789, 8 months ago

count pairs of happy elements c programing​

Answers

Answered by shaikmisba4422
1

Answer:

#include<stdio.h>

int main()

{

int N,K,X,i,j,count=0;

  scanf("%d%d",&N,&K);

  int arr[N];

  for(i=0;i<N;i++) {

    scanf("%d",&arr[i]);

    }

  for(i=0;i<N;i++)

   {

       X=arr[i];

       for(j=0;j<N;j++)

            {

               if((arr[j]>=(X-K))&&(arr[j]<=(X+K))&&(j!=i))

                {

                   count++;

                   break;

                }

            }

    }

  printf("%d",count);

}

Explanation:

thank u

Similar questions