Tuesday, March 15, 2011

Given a range find how many numbers occur within it.

You are receiving a continuous stream of numbers, at any point i'll provide a range eg: 5- 15 and the output should be the number of numbers between 5-15.

P.S. - Since the input is a stream the output can change for the same range if the function is called again.


1 comment:

  1. The code can be handled using standard file handling of C. The following code should help:

    /* Assuming that the stream is already open */
    void DisplayNum(FILE* stream, int min, int max)
    {
    int no;
    while(stream != null)
    {
    no = fgetc(stream);
    if(no>=min && no<=max) printf("%d",no);
    }
    }

    ReplyDelete