Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

Runtime error in GCD2

$
0
0

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

Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>