Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exercise 12.11 solution #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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`
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