On Wed, Apr 07, 1999, Maurizio Firmani <[EMAIL PROTECTED]> wrote:
> 
> I am looking for an algorithm which basically has to solve this problem:
> Given two floating-point numbers it has to generate a list of numbers whose the
> last digit has an increment of 1, 2 or 5. For example, if I give
> xmin=3.141592 xmax=5.003
> I will get
> 3.0  3.2  3.4  3.6  3.8  4.0  4.2  4.4  4.6  4.8  5.0  5.2 
> If I give
> xmin=-3.0308 xmax=-2.964
> I will get
> -3.03  -3.02  -3.01 -3.00 -2.99 -2.98 -2.97 -2.96
> 
> I had a look at dejanews but I couldn't find any answer.
> 
> Any suggestion on how to solve this problem or where I can search for the
> algorithm?
> Ah, the algorithms is for building axis with tick marks.

Heh, talk about a bit off topic. Anyway, I'm up for a quick challenge:

McVeigh:~% ./foo              
3.0 3.2 3.4 3.6 3.8 4.0 4.2 4.4 4.6 4.8 5.0 5.2 

Attached is the code (all 16 lines)

JE

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
  float f;
  float min = 3.141592, max = 5.003;
  /* float min = -3.0308, max = -2.964; */

  for(f = min - fmod(min, 0.2); f < (max + 0.2); f += 0.2) 
    printf("%.1f ", f);

  printf("\n");
}

Reply via email to