用scanf返回值为每次输入值的个数。。

比如:

        while(scanf("%d",&x)==1)

              a[n++]=x;

             for(i=0;i<n;i++)

              printf("%d",a[i]);