How to increment variable when term is completed

62 views Asked by At

Input places in km, people can stay in place if it's away from them less than 150 km from current place. First current place is 0.

Input:

100 120 200 300 420 500 580 645 740 870 980 1100 1230 1300 1377

Output:

2., 3., 4., 5., 6., 8., 9., 10., 11., 12., 13.
  1. First thing i did was current place+150=150
  2. Then numbers who are less than that: 100 and 120
  3. Then highest number is: 120
  4. Highest number=current place
  5. To compare next: currentplace+150 and so on.
    int less[15]={},array[15]={100, 120, 200, 300, 420, 500, 580, 645, 740, 870, 980, 1100, 1230, 1300, 1377}, i,j, current[15]={0},tmp, compare[15]={0}, bigger[15]={0};

    printf("People will stay at: \n");

    for(i=0;i<5;i++)
    {
        current[i]=150+array[i];

        if(array[i]<current[i])
        {
            less[i]=array[i];
            printf("Less are:%d\n", less[i]);
        }
    }

    printf("Max number of less number I found previousli is: ");
    for(i=1;i<15;i++)
    {
      int max=less[0];
      if(less[i]>max)
      {
        max=less[i];

        printf("\Biggerje: %d, they will stay at %d\n", max,i+1);
      }
    }

I dont know how to find max number from less[i] numbers and add it to current position within for loop

0

There are 0 answers