Why I am getting this Compilation r error: control reaches end of non-void function [-Werror=return-type]

newbie to c programming, even though I got the output in other IDE's. One of the IDE's showed this problem.

#include <stdio.h>

int max(int a, int b, int c, int d) {
    if (a>b && a>c && a>d){
        printf("%d",a);
    }
    else if (b>a && b>c && b>d ) {
        printf("%d",b);
    }
    else if (c>a && c>b && c>d ) {
        printf("%d",c);
    }
    else {
        printf("%d",d);
    }
}

int main() {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    max(a,b,c,d);
    return 0;
}

Solution 1:

The function int max(int a, int b, int c, int d) is declared to return int but does not return anything just change the declaration to void max(int a, int b, int c, int d).Or if you want to return the answer instead of printing you can just return and print in the main function.

int max(int a, int b, int c, int d) {
    if (a>b && a>c && a>d){
        return a;
    }
    else if (b>a && b>c && b>d ) {
        return b;
    }
    else if (c>a && c>b && c>d ) {
        return c;
    }
    else {
        return d;
    }
}

int main() {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    printf("%d",max(a,b,c,d));
    return 0;
}