Functions in C

  • + 0 comments
    #include <stdio.h>
    #include<stdbool.h>
    
    int max_of_four(int a, int b, int c, int d) {
        
        while (true) {
            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 if ((d > a && d > b) && (d > c)) {
                return d;
            }
        }
        return 0;
        
    }
    
    
    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;
    }    
        return 0;
    
    
    /*
    	I want to share my solution to this challenge.
    
    I used a while loop to compare which letter is greater than the rest.
    
    However, I would like to receive some suggestions to see if my solution is really valid or if it can be improved. Thank you very much.
    
    */
    }