• Post Reply Bookmark Topic Watch Topic
  • New Topic

Missing numbers from a sequence  RSS feed

 
divya madala
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Can anybody give me a code where I should have the output of missing numbers from a sequence.
For example if I have a list
12340
12342
12343
12345
12346
12347
12348
12350
then my output should be 12341,12344,12349. I know this's a homework assignment, but I would appreciate any help you could offer.
Thanks for your help,
Divya
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without giving too much away, here's a general approach. You want two control numbers, one representing the value from the file, and another representing the next number in the sequence.
Read in the first number and convert it to an integer, saving the value twice, both as the file value and the sequence value. Then set up a loop where you compare the two values (which will be the same the first time through the loop). If they are the same, then read in the next value and increment the sequence number. If they are different, print out the sequence number and increment it, but don't read in a value from the file.
Keep looping until you run out of values.
I could have described this more cleanly in pseudo-code, but I didn't want to give too much away.
Try coding it, and when you run into something you can't solve post the code that you have and get further comments.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!