Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7023643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:44:12+00:00 2026-05-27T23:44:12+00:00

I wrote 2 functions: PrintIdentical -receives 2 arrays and their sizes – sorts them

  • 0

I wrote 2 functions:
PrintIdentical -receives 2 arrays and their sizes – sorts them and than call to function
bin_search_print that needs to search each element from the small array inside the big array and print it if found.
i have a bug – the bin_search_print function found the first element and print the first element in a loop and not reaching the other elements.

void bin_search_print(int key,int *a,int n)
{
    int low,high,mid;
    low=0;
    high=n-1;
    while(low <= high)
    {
        mid=(low+high)/2;
        if(key==a[mid])
            printf ("%d", mid);
        return mid;
        else if(key<a[mid])
            high=mid-1;
              else   /* key >a[mid] */
            low=mid+1;
    }
    return -1;
}

void PrintIdentical(int arrA[], int arrA_size, int arrB[], int arrB_size)
{
    int i;
    int smaller;
    int *newarr;
        merge_sort(arrA, 0, arrA_size);
        merge_sort(arrB, 0, arrB_size);

         if(arrA_size>arrB_size)
         {
          smaller=arrB_size;
                 for(i = 0; i < smaller; i++) {     
                    bin_search_print(arrB[i], arrA, arrA_size+1);
                 }
         }
         else
          {
          smaller=arrA_size;
                 for(i = 0; i < smaller; i++) {     
                    bin_search_print(arrA[i], arrB, arrB_size+1);
                 }
         }

}

A[1,2,3,4,5]
B[1,4,3,9]

I need to print 1 4 3

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:44:13+00:00Added an answer on May 27, 2026 at 11:44 pm

    bin_search_print is missing a return after the printf.

    if (key == a[mid]) {
      printf("%d", key);
      return;
    } else {
      if (key < a[mid]) {
        high = mid - 1;
      } else {
        /* key > a[mid] */
        low = mid + 1;
      }
    }
    

    Additional notes:
    bin_search_print is declared as void and should not return a value.

    Please use curly braces with your if statements!

    Please turn on compiler warnings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a beginner in JavaScript but I wrote two functions that is meant
I wrote a function in Java to fetch 10 links by their IDs from
I wrote a .net assembly using c# to perform functions that will be used
I wrote up a quick memory reader class that emulates the same functions as
I wrote 3 functions that count the number of times an-element appears in a-list.
I wrote a research project in matlab that uses quite a few functions which
I wrote functions that allow the user to select and de select divs by
Back in VB6, I wrote a few functions that would let me code without
For a small to-be-embedded application, I wrote a few functions + struct that work
I wrote a neural network object in python that has a cost function and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.