Answer to Question #288999 in C for rohini

Question #288999

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


1
Expert's answer
2022-01-20T01:45:59-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS