suppose the input is 1,2,3,5-14,16-20,-25,31-
:the program must print
output: 1
2
3
5 6 7 8 9 10 11 12 13 14
16 17 18 19 20
0 1 2 3 ...........25
31 32 33..... til end of file
I WAS REJECTED FROM MY LAST ROUND OF INTERVIEW BECAUSE I MADE THE CODE BIG.. PLZ CAN ANY1 HELP ME WIT OPTIMISED CODE. :)
raj REDDY
0
Newbie Poster
Recommended Answers
Jump to PostYou have a stop variable. Every number that is single, is given a "stop" equal to, the first number read, meaning no other numbers will be printed beyond the first one. Otherwise, stop is given the value of the number after the hyphen (the second number).
So I picture this …
Jump to PostI would ask a few questions:
"31 32 33..... til end of file". What does end of file mean here? Are you reading input from a file? Are you just printing numbers until the user tells you to stop? The behavior isn't obvious here, so writing code for it is …
All 5 Replies
Adak
419
Nearly a Posting Virtuoso
Lucaci Andrew
140
Za s|n
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
raj REDDY
0
Newbie Poster
raj REDDY
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.