GCD2 : Code working fine , but getting wrong answer error from judge.Please Help

#include<bits/stdc++.h>
using namespace std;

int gcd(int a, int b)
{
if(b==0)
    return a;
else
    return gcd(b,a%b);
}

int main(){
int t,a,i,l; char n[251],b;
cin>>t;
while(t--){
	
	b=0;
	
	scanf("%d%s",&a,n);
	l=strlen(n);
	if(a==0){
		printf("%s\n",n);
		continue;
	}
	for(i=0;i<l;i++)
	b=(b*10+(n[i]-'0'))%a;
	cout<<gcd(a,b)<<endl;
}
return 0;
}

Yes it will give you wrong answer since you have taken b as a char(in your main function) whereas you are supposed to treat it as a integer. Rest of your code is just perfect. You can see your corrected code here.

1 Like

Ohh boy , I missed that b variable being declared under char data type… Thanks