Tuesday, July 14, 2009

Write a C program to read in a list of integers from the screen and expand them.?

Ok here is the brief decription:


if


input : 1 2-7 8-12


then the output should be


output: 1 2 3 4 5 6 7 8 9 10 11 12


now the input doesn;t have to be in a sequence,


for example


input : 1 5-7 8-11


then the output should be


output : 1 5 6 7 8 9 10 11


basically it expands the integers represented by '-',but prints out the other integers just as it is.


Can anybody give me a hint or a sample prog. how to implement this ?


Thank you.

Write a C program to read in a list of integers from the screen and expand them.?
1. take the input string and tokenize it by " ". This'll give you an array of "1" "2-7" "8-12"


2. for each element in this array:


if the string does not have "-" then print it out


else tokenize by "-" and convert to integer so you'll have an array of startpoint=2 and endpoint=7 (in the case of "2-7")


for(i=startpoint; i%26lt;endpoint; i++) print out i
Reply:Agree with "Buck Boy" and support some how what "icnintel" in such people should show hints and pseudo codes, but it angers me seeing people answering straight with full source code.





Hint:


1.) Read the whole as a string


2.) tokenize the string by a delimited by spaces


3.) for each tocken display the content unless it contains a dash


4.) if dashes were detected, detect the character before and after the dash, convert them into integers and loop to display them





Good luck
Reply:Sample programs, NO.


Hints, YES.


Hint: Read your textbook!





BTW, I think it should be a policy on these forums not to answer homework questions as posted by you. You have shown no attempt at starting this but is already asking for help.


Come up with a solution and if you are stuck we'll answer your questions but don't expect people to *do* your work for you. It's highly unethical.


No comments:

Post a Comment