# A few complicated progams to solve

## Replies

 c student · December 24, 2014 here is f2, though you might need to add an error check for valid a and b number range``#include #include #include #include typedef enum {    FALSE,    TRUE,} boolean;void testf2 ();int f2 (unsigned int, unsigned int);int main() {        unsigned int a;    unsigned int b;        testf2();        int err = scanf("%u%u", &a, &b);    if (err != 2 || err == -1) {        fprintf (stderr, "Input error\n");        abort();    }    f2 (a, b);    return 0;}// function to test function f2void testf2 () {        assert (f2(492383, 92) == 1);    assert (f2(204, 92) == 0);    assert (f2(3, 92) == 0);    assert (f2(34, 34) == 1);    assert (f2(130, 13) == 1);    assert (f2(200000000, 000) == 1);    assert (f2(258703, 25870) == 1);    assert (f2(69, 6) == 1);    }int f2 (unsigned int a, unsigned int b) {        // default value    boolean result = FALSE;        // printing numbers into strings    char str1[12];    if (sprintf (str1, "%d", a) < 0) {        fprintf (stderr, "Argument error\n");        abort();    }    char str2[12];    if (sprintf (str2, "%d", b) < 0) {        fprintf (stderr, "Argument error\n");        abort();    }        // finding substring of string    if (strstr (str1, str2) != NULL) {        result = TRUE;    }        return result;}``i'm not exactly sure what you mean in your description of function 1, perhaps you could clarify? Tom Bouhraoua · December 25, 2014 f1 is used in first program, it isn't needed for program 2.Thank you for effort, but I can't use this because we can't use strings, assert or enum. I don't even know what that is. We are at functions currently and pointers so program should look much more simpler... c student · December 25, 2014 could you provide more example output for the first function? Tom Bouhraoua · December 25, 2014 First to ask you, can you solve this function f2 in any simpler way, is it possible?And for f1 (output):Number of elements: 5Elements: 6 7 8 9 0Index p1: 1Index p2: 3TRUENumber of elements: 7Elements: 5 6 9 2 3 4 5Index p1: 2Index p2: 6FALSESo, program should compare elements between two numbers on which pointers point (including those two numbers) and if every next element in array is bigger than number before, program should write TRUE.
• 1

## C

131,236 followers