this uVA PROBLEM 10327

#include

using namespace std;

int main()
{
    int counter=0,temp,test,n=0,a[1010];
    while((cin >> test)!=0)
    {
        for(int i=0;i<test;i++)
        {
            cin >> a[i];
            n++;
        }
        for(int i=1;i<n;i++)
        {
            for(int j=0;j<n-i;j++)
            {
                if(a[j]>a[j+1])
                {
                    temp=a[j];
                    a[j]=a[j+1];
                    a[j+1]=temp;
                    counter++;
                }
            }
        }
        cout << "Minimum exchange operations :" << counter;
    }
    return 0;
}

this code shows runtime error why?

i have corrected your program, check out the link and compare it with yours : http://ideone.com/J1xwMY

//