Skip to content

Conversation

@abdallahalsamman
Copy link

exercise 12.11 solution fails with this example

#include <stdio.h>
#include <stdbool.h>

int find_largest(int a[], int n) {

        int *p = a;
        int largest = *p++;

        while (p++ < a + n) {
                if (*p > largest) {
                        largest = *p;
                }
        }
        return largest;
}

int main(void) {
        int a[] = {1,4,2,3};
        printf("Largest number is: %d", find_largest(a, 4));
}

Expected result: Largest number is: 4
Actual result: Largest number is: 3

exercise 12.11 solution fails with this example

```
#include <stdio.h>
#include <stdbool.h>

int find_largest(int a[], int n) {

        int *p = a;
        int largest = *p++;

        while (p++ < a + n) {
                if (*p > largest) {
                        largest = *p;
                }
        }
        return largest;
}

int main(void) {
        int a[] = {1,4,2,3};
        printf("Largest number is: %d", find_largest(a, 4));
}
```

Expected result: `Largest number is: 4`
Actual result: `Largest number is: 3`
@abdallahalsamman abdallahalsamman closed this by deleting the head repository Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants