Idea: First of all unordered natural number sequence (ascending), and then define I and J points to the two ends of the sequence, referring to the sum of two and M compared, larger than M, then J left shift, smaller than m, then I move right.
The code is as follows:
#include <stdio.h>
#include <stdlib.h>
Quick Line
void sort (int *a, int left, int. right)
{
if (left >= right)
{
return;
}
int i = left;
int j = right;
int key = A[left];
while (I < j)/* control in the group look for once * *
{
Two-way comparison
while (I < J && Key <= A[j])
{
j--; Looking forward
}
A[i] = A[j]; Swap location
while (I < J && Key >= A[i])
{
i++; Looking backwards
}
A[J] = A[i]; Swap location
}
A[i] = key;
Sort (A, left, i-1);
Sort (A, i + 1, right);
}
int main ()
{
int a[10] = { -2,1,3,4,-5,12,45,34,23,9};
int M = 26;
int I, J;
for (i = 0; i <; i++)
printf ("%d", a[i]);
printf ("\ n");
Sort (A, 0, 9);
for (i = 0; i <; i++)
printf ("%d", a[i]);
printf ("\ n");
i = 0;
j = 9;
while (I < j)
{
if (A[i] + a[j] = = M)
Break
if (A[i] + a[j] > M)
j--;
Else
i++;
}
if (i! = j)
printf ("%d +%d =%d\n", a[i],a[j],m);
Else
printf ("NO find!\n");
return 0;
}
An unordered natural number sequence has n natural numbers, and the sum of the two is quickly found to be two integers of M and output. -TV