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 :
- You can’t use variables in array length if they aren’t defined as one of the comments mentioned.
- 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