Functions in C

Sort by

recency

|

841 Discussions

|

  • + 0 comments

    Functions in C are essential for writing modular, reusable, and organized code. Sky1exch login

  • + 0 comments

    include

    /* 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 res=a>b?a:b; int res1=res>c?res:c; int res2=res1>d?res1:d; return res2; }

    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

    include

    /* 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 res=a>b?a:b; int res1=res>c?res:c; int res2=res1>d?res1:d; return res2; }

    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

    Less Code:

    int max_of_four(int a, int b, int c, int d) {
        if (b > a)
            a = b;
        if (d > c)
            c = d;
        
        return (a > c) ? a : 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;
    }