We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. C
  3. Introduction
  4. Functions in C
  5. Discussions

Functions in C

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 673 Discussions, By:

recency

Please Login in order to post a comment

  • taani2021happy
    1 day ago+ 0 comments

    include

    int max_of_four(int a, int b, int c, int d){

    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 return 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|
    Permalink
  • dowiarothan
    7 days ago+ 0 comments

    include

    int add(int x, int y) { return x + y; }

    int main() { int a = 10, b = 20, sum; sum = add(a, b); printf("The sum of %d and %d is %d\n", a, b, sum); return 0; }

    0|
    Permalink
  • florin_tanasa
    1 week ago+ 0 comments
    #include <iostream>
    #include <cstdio>
    using namespace std;
    
    /*
    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 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;
    }
    
    int max_of_four(int a, int b, int c, int d) {
        int max;
        max=a;
        if(b>max){
            max=b;
        }
        if(c>max){
            max=c;
        }
        if(d>max){
            max=d;
        }
        return max;
    }
    
    0|
    Permalink
  • lalmi_ahmed22
    2 weeks ago+ 0 comments

    include

    /* Add int max_of_four(int a, int b, int c, int d) here. */ int max_two(int a, int b){ return a > b ? a : b; }

    int max_of_four(int a, int b, int c, int d){ return max_two(a, b) > max_two(c, d) ? max_two(a, b) : max_two(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|
    Permalink
  • nethmithambawit1
    3 weeks ago+ 1 comment

    What is the error of this ?

    include

    /* Add int max_of_four(int a, int b, int c, int d) here. */

    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;
    

    } int max_of_four(int a, int b,int c,int d){ int max1,max2,max3,max4;

    if(a>b && a>c&& a>d)      max1=a;
    else if(b>a && b>c&& b>d) max2=b;
    else if(c>a && c>b&& c>d) max3=c;
    else if(d>a && d>b&& d>c) max4=d;
    else printf("error!!");
    return max1,max2,max3,max4;
    

    }

    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy