使用此:
i=0;
while(array[i]){
printf("%d\n",array[i++]);
}
编辑:
的意见后,所有的,我想我会写一个简单的代码,你在你的场景中使用。我已经评论了代码。它应该可以帮助你理解一切。如果你仍然有疑问,请随意。
#include<stdio.h>
void sortera(int array[], int n, int m)
{
int tmp,i,j;
for(i=n; i<m; i++)
{
for(j=n;j<m; j++)
{
if(array[j]>array[j+1])
{
tmp=array[j];
array[j]=array[j+1];
array[j+1]=tmp;
}
}
}
}
int main(){
int i,c;
int a[100];
c=0; //this c keeps the count
for(i=0;i<100;i++){ //since 100 is the max limit
scanf("%d",&a[i]);
c++; //this is what @JackWilliams meant you to do
if(a[i]==0)
break;
}
printf("\nInput array\n");
i=0;
while(a[i])
printf("%d\n",a[i++]); //this is my snippet that prints all values
//now sorting. I changed the algo a bit that you wrote (basic idea is same though)
//This code sorts the array elements in range n..m, inclusive of n and xclusive of m
//Since arrays in c are (by default) passed by reference, you just need to sort them. No return value is required
sortera(a,0,c);
//Now I use @JackWilliam's method to print the array
printf("\nSorted Array:\n");
for(i=0;i<c;i++)
printf("%d\n",a[i]);
return 0;
}
尼斯介绍,但问题是比较容易回答,如果我们能看到的代码。 –
循环变量'i'是否包含中断后扫描的整数数? –
中断后,它进入一个排序函数,从最低到最高排序所有数字。休息后它不扫描任何东西。 – andrewjones