Regarding simple input problem

sir I tried to do it using while loop but it shows timelimit error
the code which i wrote is:
include
using namespace std;
int main()
{
int n,sum=0;
while(true)
{

	cin>>n;
	
	sum=sum+n;
	if(sum<0)
	{
		break;
	}	
	cout<<n<<endl;

}

return 0;

Hi @Megha2468
In the code that your have shared is not having closing braces after return 0; statement. Include it then your code will pass all the test cases.

Here is your corrected code :

If your doubt is clear then mark it as resolved.

sir I just forgot to copy but have written it in code
the code is getting compiled but showing timelimit error.

@Megha2468
Can you please copy paste your code in https://ide.codingblocks.com/ and then save it and share link with me, because the code that you have send above is passing all the test cases.

sir its resolved thank you

If your doubt is clear then mark it as resolved.

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.