Programme to find divisible sum pairs in array.
#include<stdio.h>
int main()
{
int arr[100],i,j,n,count=0,a;
Programme to find divisible sum pairs in the array.
#include<stdio.h>
int main()
{
int arr[100],i,j,n,count=0,a;
printf("enter number you want to enter in array and the divisor"); /* Lets enter 6 and 3 */
scanf("%d %d",&n,&a);
printf("enter elements "); /* lets enter 1
3
2
6
1
2 */
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
for(i=0;i<6;i++)
for(j=i+1;j<6;j++)
if((arr[i]+arr[j])%a==0){
count++;
}
printf("%d",count);
}
OUTPUT-> " 5 " WITHOUT QUOTES
The pairs are (1,2) (1,2) (3,6) (2,1) (1,2).
Comments
Post a Comment