Runtime error in GCD2

Why this simple code is giving me Runtime error…???

#include<stdio.h>
int gcd(int a,int b)
{
  if(b==0)
    return a;
  else
    return gcd(b,a%b);
}
  char ch[251];
int remaind(int a)  /*To calculate remainder on dividing the larger number by smaller one*/
{
  int res=0;
  int i;
  for(i=0;ch[i]!='\0';i++)
    res=(res*10+(ch[i]-'0'))%a;
  return res;
}
int main()
{
  int test,a,p;
  scanf("%d",&test);
  while(test--)
  {
    scanf("%d %s",&a,ch);
    p=remaind(a);
    printf("%d\n",gcd(a,p));
  }
  return 0;
}

@anupamsingh >> Because, in the while(test--) loop you’re calculating p = remaind(a) and in the remaind() function, there is a line

res=(res*10+(ch[i]-'0'))%a;

And, the standard for C and C++ says that “If the second operand of / or % is zero the behavior is undefined”.

Test cases might contain some tests where a is zero, and that is where your code fails.
Hence, the RTE.