Life, Universe and Everything

The code below provides a run-time error showing time limit exceeded. Any help would be appreciated. Thanks :>

#include <iostream>
using namespace std;

int main(void) {
	// your code goes here
	int n;
	while(1)
	{
	    cin>>n;
	    
	    if(n==42)
	    {
	        break;
	    }
	    else
	    {
	        cout<<n<<endl;
	    }
	}
	return 0;
}

Bro, it works fine. Are you running it without providing input?

1 Like

First give custom input then run code.

Custom input? I tried that and it works fine with custom input but when i run it without that it won’t run

Why are you running without input? There will be an infinite loop because of while(1).

It worked, Thanks!! So we had to submit with Custom inputs