Functions in C

Sort by

recency

|

868 Discussions

|

  • + 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;
    }
    
  • + 0 comments

    This is my code for C

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

    sample question with answer

  • + 0 comments

    For C

    I wrote the code from scratch just to get more practice

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