Sort by

recency

|

530 Discussions

|

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

    include

    include

    include

    include

    void calculate_the_maximum(int n, int k) { int max_and = 0, max_or = 0, max_xor = 0; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { int temp_and = i & j; int temp_or = i | j; int temp_xor = i ^ j; if (temp_and > max_and && temp_and < k) { max_and = temp_and; } if (temp_or > max_or && temp_or < k) { max_or = temp_or; } if (temp_xor > max_xor && temp_xor < k) { max_xor = temp_xor; } } } printf("%d\n%d\n%d", max_and, max_or, max_xor); }

    int main() { int n, k;

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

    }

  • + 0 comments

    Passed all Testcases

    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <stdlib.h>
    //Complete the following function.
    void calculate_the_maximum(int n, int k) {
        //Write your code here.
        int and, or, xor, i, j;
        int sla=0, slo=0, slx=0;
        for(i = 1; i<n; i++){
            for(j = i+1; j<=n; j++){
                and = i&j;
                or = i|j;
                xor = i^j;
                
                // assume largest is k and find second largest for and operation 
                if(and<k && and>sla){
                    sla = and;
                }
                
                // assume largest is k and find second largest for or operation
                if(or<k && or>slo){
                    slo = or;
                }
                
                // assume largest is k and find second largest for xor operation
                if(xor<k && xor>slx){
                    slx = xor;
                }
                
            }
        }
       
      printf("%d\n", sla);
      printf("%d\n", slo);
      printf("%d\n", slx);
      
    }
    
    int main() {
        int n, k;
      
        scanf("%d %d", &n, &k);
        calculate_the_maximum(n, k);
     
        return 0;
    }
    
  • + 0 comments

    In the description of the the problem it lists the answer to the sample problem as
    2,3,3 However, the answer is 3,3,3 from my output, for i in 1 through n, find the maximum value of the logical and, or and xor when compared againt all integers through n that are greater than i. Consider a value only if the comparison returns a result less than .... The first combination is 1,2 and that gives 0,3,3 which makes the first number 3

    include

    int main() { // a = 5 (00000101 in 8-bit binary), b = 9 (00001001 in // 8-bit binary) unsigned int a = 1, b = 2; unsigned int c=23; // The result is 00000001 printf("a = %u, b = %u\n", a, b); printf("a&b = %u\n", a & b); // The result is 00001101 printf("a|b = %u\n", a | b); // The result is 00001100 printf("a^b = %u\n", a ^ b); printf("~a = %u\n", a = ~a); // The result is 00010010 printf("b<<1 = %u\n", b << 1); printf("a>>b = %u\n", a >> b); // The result is 00000100 printf("b>>1 = %u\n", b >> 1); printf("a|b^a= %u\n", b|c); return 0; }

    yeilds:

    a = 1, b = 2 a&b = 0 a|b = 3 a^b = 3 ~a = 4294967294 b<<1 = 4 a>>b = 1073741823 b>>1 = 1 a|b^a= 23

    Also there is no scroll bar on this text window for me so I can't edit it properly.

  • + 0 comments

    void calculate_the_maximum(int n, int k) { int a, b; int AND, OR, XOR; int maxAND = 0; int maxOR = 0; int maxXOR = 0;

    for (int i = 1; i < n; i++){
        for (int j = i + 1; j <= n; j++){
            a = i;
            b = j;
            AND = a & b;
            OR = a | b;
            XOR = a ^ b;
    
            if (AND < k){
                if (maxAND < AND){maxAND = AND;}
            }
            if (OR < k){
                if (maxOR < OR){maxOR = OR;}
            }
            if (XOR < k){
                if (maxXOR < XOR){maxXOR = XOR;}
            }
            }   
        }
    printf("%d\n%d\n%d", maxAND, maxOR, maxXOR);
    

    }

    int main() { int n, k;

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

    }