Functions in C

Sort by

recency

|

862 Discussions

|

  • + 0 comments

    include

    int main() { int a, b, c, d, max;

    printf("Enter four integers: "); scanf("%d %d %d %d", &a, &b, &c, &d);

    max = a;

    if (b > max) max = b; if (c > max) max = c; if (d > max) max = d;

    printf("Maximum = %d", max);

    return 0;

  • + 0 comments

    include

    int main() { int a, b, c, d, max;

    printf("Enter four integers: ");
    scanf("%d %d %d %d", &a, &b, &c, &d);
    
    max = a;
    
    if (b > max)
        max = b;
    if (c > max)
        max = c;
    if (d > max)
        max = d;
    
    printf("Maximum = %d", max);
    
    return 0;
    

    }

  • + 0 comments

    My solution in C:

    #include <stdio.h>
    /*
    Add `int max_of_four(int a, int b, int c, int d)` here.
    */
    int max(int x,int y){
        if(x > y){
            return x;
        }
        return y;
    }
    
    int max_of_four(int a, int b, int c, int d){
        int ans = max(a,b);
        ans = max(ans,c);
        ans = max(ans, d);
        return ans;
    }
    
    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 <stdio.h>
    int max_of_four(int a,int b,int c,int d){
        int arr[4]={a,b,c,d};
        int max=arr[0];
        for(int i=1;i<4;i++){
            if(arr[i]>max){
                max=arr[i];
            }
        }
        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

    Function in C.

    Here is my Solution of the problem :

    #include <stdio.h>
    
    int max_of_four(int a, int b, int c, int d) {
    
        int max = -2147483648;
    
        if (a > max) 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 maximum = max_of_four(a, b, c, d);
    
        printf("%d\n", maximum);
        
        return 0;
    }