Friday, October 14, 2011

Write a C program to find number of pairs of adjacent numbers whose sum is 8 in a given list of items? (Example : i/p: 2 4 5 3 1 7 1 7 4 5 output: 4 )

#include
int main()
{
int l[10],a,b,c=0,s;
printf("Enter the size of array You want :-");
scanf("%d",&a);
printf("Enter the elements in the array :-\n");
for(b=0;b {
scanf("%d",&l[b]);
}
printf("\nThe elements in the array are :-");
for(b=0;b {
printf(" %d",l[b]);
}
printf("\n");
printf("Enter your sum number :-");
scanf("%d",&s);
for(b=0;b {
if (l[b]+l[b+1]==s)
c=c+1;
}
printf("Adjacent numbers whose sum is \'%d\' having pairs are : \'%d\'\n",s,c);
}

No comments:

Post a Comment