Divisible Sum Pairs-Hackerrank

Problem statement:
Problem can be found in hackerrank follow this to solve the problem
https://www.hackerrank.com/challenges/divisible-sum-pairs/problem

Explanation:

HOW TO SOLVE:
use two loops and add each existing pair and check whether the sum is divisible by given k or not.
Code to do:
#include
int main( )
{
int i,j,array[100],k;
int count=0;
scanf("%d %d",&n,&k);
for(i=n-1;i>=0;i--)
scanf("%d",&array[i]);
for(i=n-1;i>=0;i--)
for(j=n-1;j>=0;j--)
if((array[i]+array[j])%k = =0)
count+=1;
printf("%d",count);
return 0;
}
This code calculates the sum of all available pairs and checks whether sum is divisible by k or not .
If divisible increment count else skip.
The number of iterations here will be n*n.
Other Method:
Calculate the sum of all digits and subtract each element and check whether difference is divisible by k or not.
If divisible increment the count,else skip.
#include
int main( )
{
int i,j,k,array[100],count=0,sum=0;
scanf("%d %d",&n,&k);
for(i=n-1;i>=0;i--)
{
scanf("%d",&array[i]);
sum+=array[i];
}
for(i=n-1;i>=0;i--)
if((sum-array[i])%k==0)
count+=1;
printf("%d",count);
return 0;
}
The number of iterations for this method is n
So number of iterations are less ,so this is efficient over the first method.