mercredi 25 août 2021

How to define a multidimensional array in C++ with 'n' rows and 'm' columns and iterate values using For Loop?

I want a program that asks the number of rows and columns of the multidimensional array and then using For loop iterate values in the array.

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, m, x;
    int a[n][m];
    cin>>n>>m;
    for(int i; i<n ; i++)
    {
        for(int j;  j<m ; j++)
        {
            cout<<"Enter the values";
            cin>>x;
            a[i][j] = x;
        }
    }
    return 0;
}

here it gets error:

main.cpp|6|warning: 'm' is used uninitialized in this function [-Wuninitialized]|
main.cpp|6|warning: 'n' is used uninitialized in this function [-Wuninitialized]|

Aucun commentaire:

Enregistrer un commentaire