Sort by

recency

|

1949 Discussions

|

  • + 0 comments

    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;

    cin >> a >> b >> c >> d;
    
    int result = max_of_four(a, b, c, d);
    cout << result << endl;
    
    return 0;
    

    }

  • + 0 comments

    Using ranged for loop

    int max_of_four(int a, int b, int c, int d){
        int values[] = {a,b,c,d};
        int largest=a;
        for (int i: values){
            if (largest<i){
                largest=i;
            }
            i++;
        }
        return largest;
        
    }
    
  • + 0 comments
    #include <iostream>
    #include <cstdio>
    #include <algorithm> 
    using namespace std;
    
    
    int max_of_four(int a, int b, int c, int d){
      int max_value = max({a, b, c, d});
      return max_value;
    }
    
     
        
        return 0;
    }
    
  • + 0 comments
    #include <stdio.h>
    
    int max(int arr[4]) {
        int maximum = arr[0];
        for (int i = 1; i < 4; i++) {
            if (arr[i] > maximum) {
                maximum = arr[i];
            }
        }
        return maximum;
    }
    
    int main() {
        int arr[4];
        
        for (int i = 0; i < 4; i++) {
            scanf("%d", &arr[i]);
        }
        
        printf("%d\n", max(arr));
        
        return 0;
    }
    
  • + 0 comments

    ** 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;
    }
    

    }

    **