Answer to Question #240666 in C++ for jan

Question #240666
Q: Explain the given code in your own words.

 find(X): traverse the array until X is located.
 int find(int X)
 {
    int j;
    for(j=1; j < size+1; j++ )
    if( A[j] == X ) break;
    if( j < size+1 ) {  // found X
    current = j;       // current points to where X found
    return 1;  // 1 for true
  }
    return 0; // 0 (false) indicates not found






1
Expert's answer
2021-09-24T18:58:20-0400


find(X): traverse the array until X is located.
// define a function find(x) that takes the an integer x and traverse the array to find the location of x
 int find(int X)
 {
    int j;
    for(j=1; j < size+1; j++ )
    if( A[j] == X ) break;
    if( j < size+1 ) {  // X is found
    current = j;       // store the points where x is found in aa variable current 
    return 1;  // return 1 if x is found
  }
    return 0; // return 0 if x is found

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