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;
}