How to find the next number in the series 14, 25, 47, 91 with C

1 Answer

0 votes
#include <stdio.h>

/*
25 - 14 = 11
47 - 25 = 22
91 - 47 = 44

11 -> 22 -> 44 -> 88

91 + 88 = 179
*/

/*
    Compute the next number in the series using the rule:
    - Differences double each step.
    - Example for the given sequence:
        14, 25, 47, 91
        Differences: 11, 22, 44
        Next difference = 44 * 2 = 88
        Next value = last + 88
*/
int next_in_series(const int *arr, int size) {
    if (size < 2) {
        // Not enough data to compute a difference
        return -1;
    }

    // Last difference
    int last_diff = arr[size - 1] - arr[size - 2];

    // Apply doubling rule
    int next_value = arr[size - 1] + last_diff * 2;

    return next_value;
}

int main(void) {
    int series[] = {14, 25, 47, 91};
    int size = sizeof(series) / sizeof(series[0]);

    int next = next_in_series(series, size);

    printf("Next number in the series: %d\n", next);

    return 0;
}



/*
run:

Next number in the series: 179

*//

 



answered 6 days ago by avibootz
...