Sort by

recency

|

538 Discussions

|

  • + 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) {
      //Write your code here.
      int sumor = 0, sumand = 0, sumxor = 0; 
      for(int i = 1; i < n; i++){
        for(int j = i+1; j <= n; j++){
           if(sumand < (i & j) && (i & j) < k)
             sumand = i & j;
           if(sumor < (i | j) && (i | j) < k)
             sumor = i | j;
           if(sumxor < (i ^ j) && (i ^ j) < k)
             sumxor = i ^ j;
        }  
      }
      printf("%d\n%d\n%d",sumand,sumor,sumxor);
    }
    
    int main() {
        int n, k;
      
        scanf("%d %d", &n, &k);
        calculate_the_maximum(n, k);
     
        return 0;
    }
    
  • + 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