Sort by

recency

|

537 Discussions

|

  • + 0 comments

    You will be given an integer “n“ and a threshold “k”. For each number ‘i‘ from ‘l‘ through ‘n‘ find the maximum value of the logical and, or, and xor when compared against tall integers through “n“ that are greater than “i“. Consider a value only if the comparison returns a result less than “k“. Print the results of the and, or and exclusive or comparisons on separate lines, in that order.

  • + 0 comments

    The examples really help in understanding how these operators work at the binary level. Perfect for anyone learning about logical operations in programming. Great job! www.11xplay.pro

  • + 1 comment
    #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 maxAND = 0, maxOR = 0, maxXOR = 0;
      for (int a = 1; a < n; a++) {
        for (int b = 2; b < n + 1; b++) {
            if (b != a) {
                maxAND = (maxAND < (a&b) && (a&b) < k ) ? (a&b) : maxAND;
                maxOR = (maxOR < (a|b) && (a|b) < k ) ? (a|b) : maxOR;
                maxXOR = (maxXOR < (a^b) && (a^b) < k ) ? (a^b) : maxXOR; 
            }
        }
      }
      printf("%d\n%d\n%d\n", maxAND, maxOR, maxXOR);
    }
    
    int main() {
        int n, k;
      
        scanf("%d %d", &n, &k);
        calculate_the_maximum(n, k);
     
        return 0;
    }
    
  • + 0 comments

    It's essential to ensure the conditions are well-formed to avoid unexpected behavior. Always ensure that the loop has a clear exit condition to prevent infinite loops Sky1exchange

  • + 0 comments

    the problem specification is poorly written: only consider pairs for 1 -n and numbers greater than that: ex 1,2 ; 1,3; 1,4 2,3; 2,4 3,4; 4&4 is 4, so if you consider the number to itself it will always be k-1; if you use loops, one loop goes from 1 to n-1, the other from (index +1) to n.