Lỗi #define trong codeblock

Mọi người ơi cho em hỏi sao #define trong codeblock lại gặp lỗi này vậy ạ

#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <cmath>
#include <string.h>
#include <windows.h>


using namespace std;

#define n 5

void nhap_mang(int a[],int n)
{
    for(int i=0;i<n;i++)
        {
            cout<<"nhập phần tử thứ a["<<i+1<<"] : ";
            cin>>a[i];
        }
}

void xuat_mang(int a[],int n)
{
    for(int i=0;i<n;i++)
        {
            cout<<"phần tử thứ a["<<i+1<<"] : "<<a[i]<<"\n";
        }
}

int tim_kiem_tuyen_tinh(int a[],int n,int x)
{
    for(int i=0;i<n;i++)
        {
            if(a[i]==x)
                {
                    return 1;//true
                }
        }
        return 0;//false
}

int tim_x_xuat_hien_bao_nhieu_lan(int a[],int n,int x)
{
    int dem=0;
    for(int i=0;i<n;i++)
        {
            if(a[i]==x)
                {
                    dem++;//true
                }
        }
    return dem;

}

int main()
{
    SetConsoleOutputCP(65001);
    int a[100];
    int n;
    printf("nhập n : ");
    scanf("%d",&n);

    nhap_mang(a,n);
    xuat_mang(a,n);
    int x;
    printf("nhập x : ");
    scanf("%d",&x);
    int ketqua=tim_kiem_tuyen_tinh(a,n,x);
    if(ketqua==1)
        {
            printf("tìm thấy\n");
        }
    else
        {
            printf("không tìm thấy\n");
        }
    cout<<x<<" xuất hiện số lần là : "<<tim_x_xuat_hien_bao_nhieu_lan(a,n,x)<<"\n";

    return 0;
}

#define n 5 nó sẽ thay thế tất cả mọi n thành số 5
thì lấy ví dụ hàm nhap_mang đi
nó sẽ thành như này:

void nhap_mang(int a[], int 5)
{
    for (int i = 0; i < 5; i++)
    {
        cout << "nhập phần tử thứ a[" << i + 1 << "] : ";
        cin >> a[i];
    }
}

nhìn ra vấn đề chưa :slight_smile:

7 Likes

cảm ơn anh,bye anh chắc off rồi

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