i tried the brute force way:
#include <stdio.h>
int sum(int a [],int b[], int m);
int main (void)
{
int a [] = {1,2,3,4,5};
int b [] = {4,3,5,2,6};
int i;
printf("Enter to find a given number:\n");
scanf("%d",&i);
printf("%s\n",sum(a,b,i) ? "True":"False");
return 0;
}
int sum(int a[], int b[],int m)
{
int i=0,j=0;
for (i=0;i<=sizeof(a)/sizeof(int)+1;i++)
for(j=0;j<=sizeof(b)/sizeof(int)+1;j++)
if (a[i]+b[j]==m)
return 1;
return 0;
}
as you can see the run time is O(n^2), are there any clever way to minimise this?