Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C++- Filling a 2D array from user input

I’m new to programming and was finding transpose of a matrix.
However, I want the input of the matrix from the user and by writing the following code, the complier doesn’t take any input values and immediately stops.
I looked into previous questions posted here about the same but found non useful.

#include<iostream>
using namespace std;
int main()
{
    int rows,val;
    int num[rows][rows];
    cin>> rows;
    for(int i=1; i<= rows; i++)
    {
        for(int j = 1; j <= rows; j++)
        {
            cin>> val;
            arr[i][j]= val;
        }
        cout<<endl;
    }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  1. You can’t use variables in array length if they aren’t defined as one of the comments mentioned.
  2. arr[i][j] inside your nested for loop isn’t declared so that would also give an error, I guess you wanted to use num array which you declared.
    The rest is all looking good
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading