我使函數刪除陣列在C其中相同的數據++,從而使這樣的過程:誤差函數刪除陣列的數據,在C++中相同
input:4
input:
25.50
64.25
64.25
25.50
output:
5.50
64.25
但像這樣的圖像的功能的錯誤
這裏的代碼
#include <iostream>
using namespace std;
void removeSame(double a[int x]){
int index[x];
for(int z=0; z<x; z++){
jum[z]=0;
for(int c=0; c<x; c++){
if(a[c]==a[z]){
index[z]=c;
}
}
}
for(int z=0; z<x; z++){
if(z==index[z]){
cout<<a[z]<<endl;
}
}
}
int main(){
int n,x;
cin>>n;
double a[n];
for(x=0; x<n; x++){
cin>>a[x];
}
removeSame(a[x]);
return 0;
}
然後當我改變這樣的代碼,再次出現錯誤
void removeSame(double a[], int x){
...
}
錯誤是這樣的:
cannot convert 'double' to 'double*' for argument '1' to 'void hapusygsama(double*, int)'
請幫我
更新。 THX爲大家誰是我的回覆線程
#include <iostream>
using namespace std;
void hapusygsama(double a[], int len){
int index[len];
for(int z=0; z<len; z++){
for(int c=0; c<len; c++){
if(a[c]==a[z]){
index[z]=c;
}
}
}
cout<<endl;
for(int z=0; z<len; z++){
if(z==index[z]){
cout<<a[z]<<endl;;
}
}
}
int main(){
int n,x;
cin>>n;
double a[n];
for(x=0; x<n; x++){
cin>>a[x];
}
hapusygsama(a, n);
return 0;
}
爲什麼你不把所有的項目插入地圖,然後打印? – aryjczyk
我很困惑,爲什麼這個'double a [n];'編譯?由於'n'不是一個常量。 –
您是否嘗試過在Google中通過查詢_「C++傳遞數組來傳遞函數」來搜索某些內容?這是一個非常受歡迎的問題。 – soon