NZEC inspite of adding return 0, working in C

#include<stdio.h>
#define size 100000
int a[size+1],b[size+1];
int main()
{
int i,j,c;long n;
while(1)
{ c=0;
scanf("%ld",&n);
if (n==0)
return;

         for (i=1;i<=n;i++)
         {
             scanf("%d",&a[i]);
         }
         for (i=1;i<=n;i++)
         {
             j=a[i];
             b[j]=i;
         }
   
    for (j=1;j<=n;j++)
    { if (a[j]==b[j])
       c++;
       else
       break;
    }
      if(c==n)
      printf("ambiguous \n");
      else
      printf("not ambiguous \n");
    } 
       
      getch(); 
      return 0;
} 

question in ambiguous permutation in practice problems -> easy

code works fine on my machine and getch() is deleted before submission

It says I delete getch() before submitted as it can cause further issues

You have a void return in one of your conditions, that might be the problem.

3 Likes

I’m not very good at c++ but I don’t think you need getch in this particular case. Why are you using it?

I also think that’s the problem.

I removed the getch (I don’t think its required) and replaced the return with a break . Got AC . Just try it out .The break statement will break out of the loop. As the others already pointed out , the return type is causing the error .

1 Like
//