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

×

# running problem in code

 4 i made a code.but while compiling time limit exceeded is displayed.so how can i run this program. asked 23 May '12, 20:49 2★prachi94 61●2●3●4 accept rate: 0% 16.9k●49●115●225

 3 @prachi94 I think you are talking about your following code: #include 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 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. }  answered 23 May '12, 21:43 3.7k●4●25●49 accept rate: 27%
 0 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. answered 23 May '12, 20:56 16.9k●49●115●225 accept rate: 11%
 0 Answer is hidden as author is suspended. Click here to view. answered 26 May '12, 02:42 (suspended) accept rate: 0%
 toggle preview community wiki:
Preview

### Follow this question

By Email:

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

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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:

×729
×690
×198

question asked: 23 May '12, 20:49

question was seen: 1,232 times

last updated: 26 May '12, 02:42