这是题目:
#include <stdio.h>
int bubble(int *p,int j; //"bubble" means using bubble sort
int main()
{
int number,i;int z; //"number" is the number you want
scanf("%d",&number);
int ch[number]; //q is quantity of the array"ch"
for(i=0;i<number;i++) //i is used to put the number into array
{
scanf("%d",&ch[i]);
}
bubble(ch,number); // make the array to the function "ch"
for(z=0;z<number;z++)
{
printf("%d",ch[z]);
if(z!=(number-1))
{
printf(" "); //do the " " thing
}
}
return 0;
}
int bubble(int *p,int j)
{
int x,y; //these variable are used to do the bubble sort
int t; //t is used to exchange variables
for(x=0;x<j;x++)
{
for(y=0;y<=j-x-1;y++)
{
if(p[y]<=p[y+1])
{
t=p[y+1];
p[y+1]=p[y];
p[y]=t;
}
}
}
}
两个例子,为什么会有差别?
对的:
错的: