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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:50:52+00:00 2026-06-15T05:50:52+00:00

I’m trying to pass a user-defined array (defined here as matrix1) into a function

  • 0

I’m trying to pass a user-defined array (defined here as matrix1) into a function (det) with the aim of calculating the determinant.
Any help would be appreciated, I’m sure there’s an easy way to do this, but my various attempts using pointers/vectors have been futile!

#include <iostream>
#include <math.h>
#include <vector>

using namespace std;

int c, d;

int matrix1(int nS)
{
    cout << "Enter the elements of first matrix: ";
    int matrix1[10][10];
    for (c = 0 ; c < nS ; c++ )
    for (d = 0 ; d < nS ; d++ )
        cin >> matrix1[c][d];

for (c = 0 ; c < nS ; c++ )
    {   
        for (d = 0 ; d < nS ; d++ )
            cout << matrix1[c][d] << "\t";
            cout << endl;
    }
}

int det(int nS, int matrix)
{
    int det;
    int iii;
    for (iii = 0; iii < nS; iii++)
    {
        double a;
        double b;
        int c;
        for (c = 0; c<nS; c++)
        {
//          cout << (iii+c)%nS << endl;
//          cout << (nS-1) - (iii+c)%nS << endl;
        int z = (iii+c)%nS;
        cout << c << ", " << z << endl;
            a *= matrix[c][z];
            b *= matrix[c][(nS-1) - (iii+c)%nS];
        }

    det+= a-b;
    }
    cout << det << endl;
}

int main()
{
    cout << "Enter the number of rows and columns of matrix: ";
    int nS;
    cin >> nS;

    matrix1(nS);

    det(nS, matrix1);

    return 0;
}
  • 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-15T05:50:53+00:00Added an answer on June 15, 2026 at 5:50 am

    You have to declare the array inside your main function for other functions to access it as well. An array declared inside a function other than main has a local scope on the stack and it gets destroyed as soon the function body gets executed.

    That being said, you have two entities with the same name, a matrix array and a function. This wont compiler so make their names unique. Declare your matrix array in main like this.

    int matrix[10][10] ;
    

    Now pass it to your input function matrix1 like this.

    matrix1(matrix, nS) ;
    

    And your matrix function would be like this.

    int matrix1(int matrix[][10], int nS)
    {
      //code runs here
    }
    

    You can pass it to the det function as well in a similar fashion. And it is better if you make the row and column numbers as const so that you can change them later in your program easily.

    const int ROWS = 10 ;
    const int COLS = 10 ;
    

    You can learn more on why the column number is passed and how a 2D array gets passed to a function in a similar answer here.

    2D-array as argument to function

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
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
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.