• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Missing numbers from a sequence

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
No matter how many women are assigned to the project, a pregnancy takes nine months. Much longer than this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic