Functions in C

Sort by

recency

|

848 Discussions

|

  • + 0 comments

    include

    int max(int x, int y){ return (x > y) ? x : y; }

    int max_of_four(int a, int b, int c, int d){ return max(max(a, b), max(c, d));
    }

    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

    Here is Functions in C problem solution - https://programmingoneonone.com/hackerrank-functions-in-c-problem-solution.html

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

    This program defines a function max_of_four to find and return the greatest of four integers using basic comparisons. It's a simple example of how to use functions in C for modular and reusable code. Cricketbuzz.com

  • + 0 comments
    #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", ans);
        
        return 0;
    }