On Dec 28, 2007 6:06 AM, Nehru <[EMAIL PROTECTED]> wrote: > > Dear all, > > I'm a beginner in C. > > I've an array which has a set of elements say for example > 23,24,25,34,35,36,37,44,6,7,8,9. > > so i should get the output as > 23-25,34-37,44-44,6-9. > > I tried a little. but i don't know to bring it in the program. > Can anyone help me?
Print first number. While (more numbers) if next number != last number+1 print "-" + last number + "," + this number end if last number = number before + 1 print "-" + last number else print last number end There'll be a few cases where this algorithm won't work, but it'll give you an idea of how to start. -- PJH http://shabbleland.myminicity.com/