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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:47:48+00:00 2026-06-02T16:47:48+00:00

i want the user to input values in a 2 dimensional array. he can

  • 0

i want the user to input values in a 2 dimensional array. he can also choose the size of each dimension

    int main()
{
    int x;
    int y;
    int *p;
    cout<<"How many items do you want to allocate in dimension x?"<<endl;
    cin>>x;
    cout<<"How many items do you want to allocate in dimension y?"<<endl;
    cin>>y;
    p = new int[x,y];
    for(int i=0; i<x; i++)    //This loops on the rows.
    {
        for(int j=0; j<y; j++) //This loops on the columns
        {
            int value;
            cout<<"Enter value: "<<endl;
            cin>>value;
            p[i,j] = value;
        }
    }
    drill1_4 obj;
    obj.CopyArray(p,x,y);

}

and then, ill output the two dimensional array via

class drill1_4
{
public:
    void CopyArray(int*,int,int);
private:
    int *p;
};

void drill1_4::CopyArray(int* a,int x,int y)
{
    p = a;
    for(int i=0; i<x; i++)    //This loops on the rows.
    {
        for(int j=0; j<y; j++) //This loops on the columns
        {
            cout << p[i,j]  << "  ";
        }
        cout << endl;
    }
    getch();
}

logic seems fine, but lets say, if the user enters the numbers, the array should look like this

1 2

3 4

but instead, it looks like this:

3 3

4 4

The array is not displaying it correctly.

  • 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-02T16:47:49+00:00Added an answer on June 2, 2026 at 4:47 pm

    I don’t know if you figured out the answer to your problem. The comments above tell you where you went wrong. Here is a possible answer.

    #include <cstdio>
    
    #include <iostream>
    using namespace std;
    
    class drill1_4
    {
    public:
        void CopyArray(int**,int,int);
    private:
        int **p;
    };
    
    void drill1_4::CopyArray(int** a,int x,int y)
    {
        p = a;
        for(int j=0; j<y; ++j)    //This loops on the rows.
        {
            for(int i=0; i<x; ++i) //This loops on the columns
            {
                cout << p[i][j]  << "  ";
            }
            cout << endl;
        }
        cin.get();
    }
    
    
       int main()
    {
        int x;
        int y;
        int **p;
        cout<<"How many items do you want to allocate in dimension x?"<<endl;
        cin>>x;
        cout<<"How many items do you want to allocate in dimension y?"<<endl;
        cin>>y;
        p = new int*[x];
        for (size_t i = 0; i < x; ++i)
            p[i] = new int[y];
    
        for(int j=0; j<y; ++j)    //This loops on the rows.
        {
            for(int i=0; i<x; ++i) //This loops on the columns
            {
                int value;
                cout<<"Enter value: "<<endl;
                cin>>value;
                p[i][j] = value;
            }
        }
        drill1_4 obj;
        obj.CopyArray(p,x,y);
    }
    

    I am not sure I understood what you meant by x-dimmension. If you meant x running horizontally than I think that i and j for-loops shout be reversed as x will represent columns.

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

Sidebar

Related Questions

Requirement is like: I want to take input values from user in frame but
If I want to create a 2D array, with dimensions specified by user input,
I want to develop something similar to jsfiddle in where the user can input
I have an input edit field where the user can enter data. I want
num = input('Enter the size') I want to create a 2 dimensional matrix matrix
i want to get matrix values, rows and coloumn from user input. So i'm
want to make values of the oject's dynamic (from user input) but I get
i want to read 2 values from user input using lisp. I want to
How can I change the values in XAML based on user input from a
I want to print the values on crystal report that user input on the

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.