Runtime error in C

Can somebody tell me why i am getting runtime error for this C program ?(i have the same error with my other programs as well).Its working fine in my compiler.

#include<stdio.h>
int main()
{
	int i,n,a[10000],b[10000],flag,index;
	while(1)
	{
		scanf("%d",&n);
		if(n==0)
		  break;
		flag=0;
	   for(i=0;i<n;i++)
	   {
		  scanf("%d",&a[i]);
		  index=a[i]-1;
		  b[index]=i+1;
		}                                                                                                                                                                                                                                      
		for(i=0;i<n;i++)
		{
			if(a[i]!=b[i])
			  flag++;
		}		
		if(flag==0)
		printf("ambiguous\n");
		else
		printf("not ambiguous \n");
	}
	return(0);
}

Your program will not end if there is no 0 in input, you should try
while(scanf("%d",&n)==1)
{
if (n==0) break;
.
.
.
}

The first line of each test case
contains an integer n (1 ? n ?
100000). Then a permutation of the
integers 1 to n follows in the next
line. There is exactly one space
character between consecutive
integers. You can assume that every
integer between 1 and n appears
exactly once in the permutation.

it says “100000”. have a look at your a and b arrays … :slight_smile:

i tried it…but its not working…besides the the program is supposed to end only when there is a 0.