M, N was not declared in this scope

Lỗi này sửa sao mọi người em để int a[m][n] ra sau của hàm xuất và hàm nhập thì nó lại báo main.cpp:10:30: error: use of parameter outside function body before ‘]’ token
void xuat(int m,int n,int a[m][n]);
void nhap(int m,int n,int a[m][n]);

#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <math.h>

using namespace std;
void xuat(int a[m][n],int m,int n);
void nhap(int a[m][n],int m,int n)

int main()
{
    /*int arr[][4]=
    {
      {1,2,3,4},
      {5,6,7,8},
      {9,8,7,2}
    };*/
    int m,n;
    printf("nhap m : ");
    scanf("%d",&m);
    printf("nhap n : ");
    scanf("%d",&n);
    
    int arr[m][n];
    nhap(m,n,arr);
    
    xuat(m,n,arr);

    return 0;
}
void xuat(int a[m][n],int m,int n)
{
    //int a[m][n];
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++)
        {
            cout<<"phan tu thu a["<<i<<"]"<<"["<<j<<"] : "<<a[i][j]<<"\n";
        }
    }
}

void nhap(int a[m][n],int m,int n)
{
    
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++)
        {
            printf("nhap phan tu thu a[0][1] = [2]",i,j,&a[i][j]);
            cout<<"\n";
        }
    }
}

Thay nó bằng số cố định. Khai báo kiểu tham số của tham số không được phép.

4 Likes

Bạn viết như thế thì tham số đúng sẽ là T a** và phải xin cấp phát luôn.

Với lại xem lại tham trị với tham biến.

5 Likes
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?