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 7562055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:19:05+00:00 2026-05-30T13:19:05+00:00

i’m trying to figure out how to fill a multidimentional array in this way:

  • 0

i’m trying to figure out how to fill a multidimentional array in this way:
Input: rows = 3 , cols = 3 :

1 4 7
2 5 8
3 6 9

can somebody give me an idea?

P.S My task is to find how many nubers stay in the same position in both arrangements. Ex:

1 4 7       1 2 3
2 5 8       4 5 6
3 6 9       7 8 9

so the numbers that are in the same position are : 1 5 9.
i’ve tryied :

//n = 3 , m = 3
for(int i = 0; i <n; i++) {
for(int j = 0; j <m; j++){
if(array[i][j] == array2[i][j]) {
lol++;
}
}

}
cout<<lol;


/*
1 2 3
4 5 6
7 8 9


1 4 7
2 5 8
3 8 9
*/

it must show me 3 , but it shows 0, where is the problem?

  • 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-30T13:19:07+00:00Added an answer on May 30, 2026 at 1:19 pm

    Populate at initialization:

    int a[3][3] = { { 1, 4, 7},
                    { 2, 5, 8},
                    { 3, 6, 9}
                  };
    

    EDIT (unsure if resolved):

    After update to question here is an example application that (with modification to accept input from user) will diff two arrays and construct an array indicating the elements that were the same and a count of the number of identical elements:

    #include <iostream>
    
    int** make_array(const size_t a_rows, const size_t a_columns)
    {
        int** result = new int*[a_rows];
        for (size_t i = 0; i < a_rows; i++)
        {
            *(result + i) = new int[a_columns];
        }
        return result;
    }
    
    void print_array(int** a_array, const size_t a_rows, const size_t a_columns)
    {
        for (size_t r = 0; r < a_rows; r++)
        {
            for (size_t c = 0; c < a_columns; c++)
            {
                std::cout << *(*(a_array + r) + c) << " ";
            }
            std::cout << "\n";
        }
        std::cout << "\n";
    }
    
    int main()
    {
        // Example data.
        int a[3][3] = { { 1, 4, 7},
                        { 2, 5, 8},
                        { 3, 6, 9}
                      };
        int b[3][3] = { { 1, 2, 3},
                        { 4, 5, 6},
                        { 7, 8, 9}
                      };
        size_t rows    = 3;
        size_t columns = 3;
    
        // Create three arrays:
        //  - two input arrays
        //  - array that represents which elements are the same
        int** in_1 = make_array(rows, columns);
        int** in_2 = make_array(rows, columns);
        int** diff = make_array(rows, columns);
    
        // Populate with example data.
        for (size_t r = 0; r < rows; r++)
        {
            for (size_t c = 0; c < columns; c++)
            {
                *(*(in_1 + r) + c) = a[r][c];
                *(*(in_2 + r) + c) = b[r][c];
            }
        }
    
        // Diff.
        // The 'diff' array will hold '1' for elements that
        // were the same and '0' for elements that were not.
        size_t same_count  = 0;
        for (size_t r = 0; r < rows; r++)
        {
            for (size_t c = 0; c < columns; c++)
            {
                *(*(diff + r) + c) = *(*(in_1 + r) + c) == *(*(in_2 + r) + c);
                same_count += *(*(diff + r) + c);
            }
        }
        std::cout << "\n";
    
        // Results.
        print_array(in_1, rows, columns);
        print_array(in_2, rows, columns);
        print_array(diff, rows, columns);
        std::cout << "Same element count: " << same_count << "\n";
    
        // Free...
    
        return 0;
    }
    

    Output:

    $ ./cpp/main.exe
    
    1 4 7
    2 5 8
    3 6 9
    
    1 2 3
    4 5 6
    7 8 9
    
    1 0 0
    0 1 0
    0 0 1
    
    Same element count: 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,

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.