Write a pair of integers whose product is -12 and there lie exactly7 integers
between them.
Answers
Answered by
2
Answer:
Step-by-step explanation:
Assuming x≤y
Number of integers = max(0,⌈y⌉−⌊x⌋−1)
In short, push x down to the nearest integer and y up to the nearest integer. The difference between these integers is one more than the number of integers between. The max() function takes care of the instance where x=y and x,y∈Z, which would result in −1.
irst sort the array in nlgn and then its easy just take two pointers one pointing ats start index of array and one at the end of the array and start checking sum
like this
whwrw a is the integer array givcen
int *p;
int *q;
p=a;
q=a+n-1;
while(p!=q)
{
if(*p+*q==sum)
{printf("(%d,%d)\n",*p,*q);
p++;
q--;
continue;}
if(*p+*q<sum)
{
p++;
continue;
}
q--;
}
Similar questions