running problem in code

i made a code.but while compiling time limit exceeded is displayed.so how can i run this program.

4 Likes

You can (and you should) test your code. I’m doing it like this: I copy statement input to file (for example named test.in) and then I run

test.exe < test.in

or

test.exe < test.in > test.out

And then I compare my output with the one in statement…

You are getting TLE, you can read about the errors here.

@prachi94
I think you are talking about your following code:

#include<stdio.h>
main()
{
	int i;
	scanf("%d",&i);
	while(i!=42 || i<0)
	{
		printf("%d",i);
	}
} 

Let me highlight the problem statement:

You have to print the input and Stop processing/printing input after reading in the number 42.*

But does your solution really follow the problem statement ?

No.

Just run the while loop ,keep taking input ,check if the input is 42.If yes,break the loop ,otherwise just print the input.Well ,that’s all you have to do.

Your solution only read the input once , if the input is not 42 ,then the WHILE loop run for ever(ie. it becomes infinite loop).Your program does not terminate and that’s the reason you got a time limit.

In order to resolve it just add one extra line scanf("%d",&i); after printf("%d",i); statement:

#include<stdio.h>
main()
{
	int i;
	scanf("%d",&i);
	while(i!=42 || i<0)
	{
		
		printf("%d\n",i);//Also u were missing the newline character  here
                                     //Your soln output format and problem output format 
                                     //should match exactly
		scanf("%d",&i); //Keep taking input,if the data you read is not 42
	}
     return 0; //Don't forget return 0 ,You will get runtym error if u miss it.
}
3 Likes

I am new at this… I know some html but not very much,
I would love to get 1,000 visitors a day on my blog but it seems impossible right now
does anyone know how I could quickly optimize my blog for traffic?

<a href="http://www.kingamazon.x10.mx/wp>kindlefirecolor