陣列我是一個編程的學生,我不明白這有什麼代碼問題:問題在C
#include <stdio.h>
#include <stdlib.h>
void merge(int a[], int low, int high, int mid){
int i, j, k, c[50];
i=low;
j=mid+1;
k=low;
while((i<=mid)&&(j<=high)){
if(a[i]<a[j]){
c[k]=a[i];
k++;
i++;
} //end if
else{
c[k]=a[j];
k++;
j++;
} //end else
} //end while
while(i<=mid){
c[k]=a[i];
k++;
i++;
} //end while
while(j<=high){
c[k]=a[j];
k++;
j++;
} //end while
for(i=low;i<k;i++){
a[i]=c[i];
} //end for
} //end merge()
int mergesort(int a[], int low, int high){
int mid;
if(low<high){
mid=(low+high)/2;
mergesort(a,low,mid);
mergesort(a,mid+1,high);
merge(a,low,high,mid);
} //end if
return(0);
} //end mergesort()
int main(){
int i, n, arr[100];
do{
scanf("%d", &n);
if(n == 0)
break;
else{
for(i = 0; i < n; i++){
scanf("%d", &arr[i]);
mergesort(arr, 0, n);
} //end for
} //end else
for(i = 0; i < n; i++)
printf("%d\n", &arr[i]);
}while(n != 0); //end while
} // end main()
和終端顯示我以下錯誤
ej.c: In function ‘main’:
ej.c:60:5: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘int *’
的這個程序的目的是顯示一個排序後的數組。
告訴我們這行代碼應該用你自己的話來做,儘可能多的細節:'printf(「%d \ n」,&arr [i]);' – Jon
打印所有數組 –