Sort by

recency

|

543 Discussions

|

  • + 0 comments

    ‵‵‵c void calculate_the_maximum(int n, int k) { //Write your code here. int maxAnd = 0, maxOr = 0, maxXor = 0;

    for (int i = 1; i < n; i++) {
        for (int j = i + 1; j <= n; j++) {
            int a = i & j;
            int o = i | j;
            int x = i ^ j;
    
            if (a < k && a > maxAnd) {
                maxAnd = a;
            }
            if (o < k && o > maxOr) {
                maxOr = o;
            }
            if (x < k && x > maxXor) {
                maxXor = x;
            }
        }
        ‵‵‵
    }
    printf("%d\n%d\n%d\n", maxAnd, maxOr, maxXor);
    

    }

  • + 0 comments

    my code

    void calculate_the_maximum(int n, int k) {
      //Write your code here.
      int i=0,j=0, result[3], result_store[3], sample[n];
      for (i=1;i<=n;i++) sample[i] = i;
      for (i=0;i<=n;i++)
      {
        for (j=i+1;j<=n;j++)
        {
            if ((sample[i] & sample[j]) < k ) {result [0] = (sample[i] & sample[j]);}
            if ((sample[i] | sample[j]) < k ) {result [1] = (sample[i] | sample[j]);}
            if ((sample[i] ^ sample[j]) < k ) {result [2] = (sample[i] ^ sample[j]);}
            if (result[0]>result_store[0]) { result_store[0] = result[0]; }
            if (result[1]>result_store[1]) { result_store[1] = result[1]; }
            if (result[2]>result_store[2]) { result_store[2] = result[2]; }
        }
      }
      printf("%d\n", result_store[0]);
      printf("%d\n", result_store[1]);
      printf("%d\n", result_store[2]);
    }
    

    On running the code, it gives strange error, while in my local compiler, it works fine.

  • + 0 comments

    Salutes from Mexico :3 !

    include

    include

    include

    include

    //Complete the following function.

    void calculate_the_maximum(int n, int k) { //Write your code here. int m = 0; int m1[2] ={0}, m2[2] = {0}, m3[2]= {0};

    for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n ; j++) {

        m1[0] = i & j; 
        if (m1[0] >= m1[1] && m1[0] < k) {
            m1[1] = m1[0];
        }
        m2[0] = i | j; 
        if (m2[0] >= m2[1] && m2[0] < k) {
            m2[1] = m2[0];
        }
        m3[0] = i ^ j;
        if (m3[0] >= m3[1] && m3[0] < k) {
            m3[1] = m3[0];
        }
    }
    

    } printf("%i\n",m1[1]); printf("%i\n",m2[1]); printf("%i\n",m3[1]);

    }

    int main() { int n, k;

    scanf("%d %d", &n, &k);
    calculate_the_maximum(n, k);
    
    return 0;
    

    }

  • + 0 comments

    int maximum_and = 0, maximum_or = 0, maximum_xor = 0, and = 0 , or = 0 , xor = 0; for (int i = 1 ; i <= n ; i++) { for (int j = i+1 ; j<= n; j++) {

        and = i & j;
        or = i | j;
        xor = i ^ j;
    
        if((maximum_and < and) && (and < k))
            maximum_and = and;
        if((maximum_or < or) && (or < k))
            maximum_or = or;
        if((maximum_xor < xor) && (xor < k))
            maximum_xor = xor;
    }
    

    } printf("%d\n%d\n%d",maximum_and,maximum_or,maximum_xor);

  • + 0 comments
    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <stdlib.h>
    //Complete the following function.
    
    
    void calculate_the_maximum(int n, int k) {
      int max_xor = 0, max_and = 0, max_or = 0, or = 0, xor = 0, and = 0;
    
      for(int i = 1; i <= n; i++)
      {
        for(int j = i+1; j <= n; j++)
        {
            or = i | j;
            and = i & j;
            xor = i ^ j;
    
            if(max_or < or && k > or) max_or = or;
            if(max_xor < xor && k > xor) max_xor = xor;
            if(max_and < and && k > and) max_and = and;
        }
      }
      printf("%d \n%d \n%d \n", max_and, max_or, max_xor);
    }
    
    int main() {
        int n, k;
      
        scanf("%d %d", &n, &k);
        calculate_the_maximum(n, k);
     
        return 0;
    }