请看一下我为什么将数组一初始化就出错,不初始化就是对的???
#include <stdio.h>void sort(int *a,int n)
{
int i,j,k,t;
for(i=0;i<n-1;i++)
{
k = i;
for(j=i+1;j<n;j++)
{
if(*(a+k)<*(a+j))
k=j;
}
if(k!=i)
{
t = *(a+i);
*(a+i) = *(a+k);
*(a+k) = t;
}
}
}
int max(int *a,int n)
{
int i,max;
max = i;
for(i=0;i<n;i++)
{
if(*(a+max)<*(a+i))
max = i;
}
return (a[max]);
}
int main()
{
int i,n;
printf("Please input the number:\n");
scanf("%d",&n);
int arr[n]={0};
for(i=0;i<n;i++)
{
printf("Please input %dth number:\n",i+1);
scanf("%d",&arr[i]);
}
printf("The input number is :\n",n);
for(i=0;i<n;i++)
{
printf("%d ",arr[i]);
}
printf("\n");
sort(arr,n);
printf("Form big to small order is :\n");
for(i=0;i<n;i++)
{
printf("%d ",arr[i]);
}
printf("\n");
int maxnum = max(arr,n);
printf("The max number is:\n");
printf("%5d\n",maxnum);
}