how to reduce tle from code
My code showing tle
@Anjalisahu hi there was a simple miss, you were not reducing n i.e the number of test cases
using namespace std;
int binarytodecimal( int num)
{
int i =0;
int ans = 0;
while( num != 0)
{
int rem = num % 10;
num = num / 10;
ans += rem*pow(2,i);
i++;
}
return ans;
}
int main()
{
int n;
cin>>n;
while(n!=0)
{
int num;
cin>>num;
int p = binarytodecimal(num);
cout<<p<<endl;
nā;
}
return 0;
}
close the doubt by resolving it!
Happy coding!