Write a program that given an array A[ ] of n numbers and another number x, determine whether or not there exist two elements in A whose sum is exactly x
#include <stdio.h>
int main()
{
int m = 6;
bool exist = false;
int a[] = {1,2,3,4};
for(int i = 0; i != 4; ++i)
{
for(int j = i + 1; j != 4; ++j)
{
if(a[i] + a[j] == m)
{
exist = true;
}
}
}
if(exist)
{
printf("Found\n");
}
else
{
printf("Not found\n");
}
return 0;
}
Comments
Leave a comment