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

  • Home
  • SEARCH
  • 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 9079183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:47:04+00:00 2026-06-16T19:47:04+00:00

int count(int *a, int *b, int n) { int i=0,j=0,roz=0; while(i<n) { while(j<n) {

  • 0
int count(int *a, int *b, int n) {
    int i=0,j=0,roz=0;

    while(i<n) {
        while(j<n) {
            if(a[i]==b[j])
                roz++;
            j++;
        }
        i++;
    }
    return roz;
}

n is the size of a, or b array (both are of the same size). The nested while loop seems to work only once, for i = 0. The next thing that seems to be happening is magically changing n into 1 (it is 5 at the beginning), so that the nested while doesn’t loop the second time. Why is that so?

The interesting thing is that echoing n right before the return displays the right value, which is 5…

EDIT. For loops work properly here, but the question is still present.

  • 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-06-16T19:47:04+00:00Added an answer on June 16, 2026 at 7:47 pm

    You never reset the value of j to 0.

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

Sidebar

Related Questions

When I use new[] to create an array of my classes: int count =
#include <Windows.h> #include <stdio.h> int count = 0; FILE* pFile = 0; long Size
int count(string s){ if(s == ) return 0; if(s.length == 1) return 1; return
For the following code: auto F(int count) -> decltype([](int m) { return 0; })
I dont understand why this is forward recursion: int count(int x) { if(x<=0) return
void GameBoard::enterShips() { char location[1]; int ships = 0; int count = 1; while(ships
FileStream.Read() is defined as: public override int Read( byte[] array, int offset, int count
I have switch. One of the cases must be a count of array: int
I have some code, int count = 0; list.ForEach(i => i.SomeFunction(count++)); This seems to
I have the following: int count = args.length; Strange as it might seem I

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.