# A few complicated progams to solve

 Tom Bouhraoua · December 24, 2014 Hello to all.I'm new in programming but I'm doing my best to keep up with things I need to learn for school so I'm watching all tutorials from Bucky and I must admit they are pretty awesome and interesting.Although, I'm currently on tutorial 20 (or something like that) but I need some more complicated programs for my homework so I decided to ask for your help.I would try to do this by myself, but I have only two more days and I think I'm not capable to learn all things needed by then.I will apreciate if anyone could do at least one of them.I don't know rules of this forum, but I hope you won't find this as too big request and that you will help me. So let's start with programs.1. Write function with this prototype: int f1(int *p1, int *p2)User should enter first number of elements of array, then elements, then index of p1 and p2.Function gets two pointers which point on two elements on  array (which is integer). This function should return "TRUE" if all elements of array between *p1 and *p2 are sorted from the lowest to the biggest (including p1 and p2). If this condition isn't true, then function should return "FALSE".Also, if p1 and p2 point to same element of array function should return "TRUE", if p2 points to the element in array which is before element of p1, function should return "FALSE".Also program needs main function which allows entering array of at most 100 elements.Elements of array are integer.If user enters input index which is lower than 0 or >= number of elements, program should write "Error" and close.For example (output):Number of elements: 10Elements: 5 1 7 2 3 4 5 5 5 4Index p1: 3Index p2: 6TRUENumber of elements: 7Elements: 7 8 9 10 11 11 12Index p1: 0Index p2: 5FALSE2. Write function with this prototype: int f2(unsigned int a, unsigned int b)Function gets two numbers from user (a i b, type: unsigned int) and returns "TRUE" if b is contained in a and returns "FALSE" if not.For example (output):Enter a: 3469Enter b: 46TRUEEnter a: 3469Enter b: 9TRUEEnter a: 3469Enter b: 334FALSEEnter a: 3469Enter b: 3469TRUE3. Program works with matrix 30x30.Program should have this output:Menu:1. Dot2. Line3. Rectangle4. Circle5. Output6. ExitInput your choice: 1Input coordinate of x: 5Input coordinate of y: 5Input character: +Menu:1. Dot2. Line3. Rectangle4. Circle5. Output6. ExitInput your choice: 3Input coordinate of x (top left angle): 7Input coordinate of y (top left angle): 2Input coordinate of x (bottom right angle): 12Input coordinate of y (bottom right angle): 5Input character: =Menu:1. Dot2. Line3. Rectangle4. Circle5. Output6. ExitInput your choice: 2Input coordinate of x (start of line): 10Input coordinate of y (start of line): 10Input coordinate of x (end of line): 15Input coordinate of y (end of line): 5Input character: *Menu:1. Dot2. Line3. Rectangle4. Circle5. Output6. ExitInput your choice: 5Menu:1. Dot2. Line3. Rectangle4. Circle5. Output6. ExitInput your choice: 6END OF PROGRAM.Thanks in advance and sorry for bad English,Tom.

## Replies

 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. c student · December 25, 2014 could you provide more example output for the first function? 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 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?
• 1

## C

129,673 followers
About

One of the most popular languages of all time.

Links
Moderators
 Bucky Roberts Administrator