Functions in C

  • + 0 comments
    #include <stdio.h>
    /*
    Add `int max_of_four(int a, int b, int c, int d)` here.
    */
    int max_of_four(int a, int b, int c, int d){
        int max=a;
        int arr[4],n ;
        arr[0]=a;
        arr[1]=b;
        arr[2]=c;
        arr[3]=d;
        while(n>=0 && n<=4){
            if(max<=arr[n]){
                max=arr[n];
            }
            n++;
        }
        return max;
    }
    
    int main() {
        int a, b, c, d;
        scanf("%d %d %d %d", &a, &b, &c, &d);
        int ans = max_of_four(a, b, c, d);
        printf("%d", ans);
        
        return 0;
    }