+ 3
Whats wrong in the below program? I get a Time Limit Exceeded error.
#include <iostream> using namespace std; int main() { char a=0; while(a<256) { cout<<a<<" "; a++; } return 0; }
2 Respostas
+ 12
SoloLearn can't handle loops with iterate for too long, will cause it to timeout. Your code should work fine on desktop compilers though.
+ 2
This loop will never end.
The 'a' variable will never reach the 256 value because its overflow the ascii table whose values goes up to 127. If you define the 'a' variable as 128 it will return back to -128, and after increment it will be set to -127. This will continue until it reaches 127 and so it will back again to -128.
Set the a while variable to 127 and will have the all ascii characters printed out on the screen.
That is why the sololearn gives you a time limit exceeded error.