Functions in C

Sort by

recency

|

854 Discussions

|

  • + 0 comments

    Here is HackerRank Functions in C problem solution

  • + 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.
    
    */
    }
    
  • + 0 comments

    C is a powerful and timeless programming language — great for system-level coding and performance-critical applications! cricbet99club

  • + 1 comment
    #include <stdio.h>
    int max_of_four(int a, int b, int c, int d){
        int max = a;
        if(b > max) max = b;
        if(c > max) max = c;
        if(d > max) max = d;
        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;
    }
    
  • + 0 comments

    int max_of_four(int a, int b, int c, int d){ int max_num = a; if (max_num > b) max_num =a ; if (max_num > c) max_num =a ; if (max_num > d) max_num =a ; if(max_num < b) max_num = b; if(max_num < c) max_num = c; if(max_num < d) max_num = d;

    return max_num;
    

    } 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;
    

    }