Quantcast
Channel: Dạy Nhau Học - Latest topics
Viewing all articles
Browse latest Browse all 34351

Lỗi hàm con hay thuật toán?

$
0
0

@Tran_Hai_Anh wrote:

Không rõ sai ở đâu, in ra mảng c đều lỗi cả, các bác check giúp mình với.

#include<iostream>

using namespace std;

bool kiemtraSo(int s, int t, int c[20]){
    for(int i=t-1;i>=0;i--){
        if(s==c[i]){
            return false;
            break;
        }
    }
    return true;
}

int main(){
    int n;
    cin >> n;
    int a[20];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }

    int c[20];
    c[0]=a[0];
    int t=1;
    for(int i=1;i<n;i++){
        bool kiemtra=kiemtraSo(a[i],t,c);
        if(kiemtra==true){
            c[t]==a[i];
            t++;
        }
    }

    for(int i=0;i<t;i++){
        cout << c[i] << " ";
    }
}

Posts: 5

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 34351

Latest Images

Trending Articles