#include<iostream>
using namespace std;
bool findnumberwithsum(int A[],int length,int *num1,int *num2,int key)
{
if(NULL==A||length<=0||NULL==num1||NULL==num2)
return false;
int start=0;
int end=length-1;
int sum=0;
while(start<end)
{
*num1=A[start];
*num2=A[end];
if(*num1+*num2==key)
{
return true;
}
else
{
if(*num1+*num2>key)
{
end--;
}
else
start++;
}
}
return false;
}
int main()
{
int A[]={1,2,4,7,11,15};
int key=15;
int num1;
int num2;
int length=6;
cout<<findnumberwithsum(A,length,&num1,&num2,key)<<endl;
system("pause");
return 0;
}
时间: 2025-01-13 14:13:51