Von Neuman Loves Binary

My code is correct but time not exceeded ,so how to solve the code
#include
using namespace std;
int main() {
int N;
int no;
cin >> N;

while(N>0){
	 

	cin >> no ;
	int p=1;
	int result=0;

	while( no>0){

	  
	  int rem = no%10;
	   
	   result =  result + rem *p;   

	   p = p*2;
	   no =no/10;                      

}
     cout << result ;
}

     N =N-1;
             
        

return 0;

}

Hello @faizan_1402,

  1. Read the constraints carefully.
    Digits in binary representation is <=16
    Mistake:
    int cannot hold these many digits.
    Solution:
    change the datatype to long long int of no.

  2. The position of decrementing N is wrong.
    Solution:
    Decrement it inside the first while loop.

Hope, this would help.
Give a like if you are satisfied.

Not run code Again showing error
#include
using namespace std;

int main() {
int N;
long long int no;
cin >> N;

while(N–){

cin >> no ;
int p=1;
int result=0;

while( no>0){

  
  int rem = no%10;
   
   result =  result + rem *p;   

   p = p*2;
   no =no/10;                      

}
cout << result ;
}

 N =N-1;

return 0;
}

Hello @faizan_1402,

The way you have shared your code may introduce many syntax errors to it.
So, share it using Online Coding Blocks IDE.

STEPS:

  1. Paste your code at https://ide.codingblocks.com/
  2. Save it there.
  3. Share the URL generated.

I correct the code for you.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.