You are not logged in. Please login at to post your questions!


running problem in code

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

asked 23 May '12, 20:49

prachi94's gravatar image

accept rate: 0%

retagged 23 May '12, 20:57

betlista's gravatar image

3★betlista ♦♦

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

    int i;
    while(i!=42 || i<0)

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 ?


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:

    int 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.

answered 23 May '12, 21:43

ritesh_gupta's gravatar image

5★ritesh_gupta ♦
accept rate: 27%

edited 23 May '12, 21:59

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

test.exe <


test.exe < > test.out

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

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


answered 23 May '12, 20:56

betlista's gravatar image

3★betlista ♦♦
accept rate: 11%

Answer is hidden as author is suspended. Click here to view.

answered 26 May '12, 02:42

marcswing's gravatar image

accept rate: 0%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 23 May '12, 20:49

question was seen: 1,232 times

last updated: 26 May '12, 02:42