• + 0 comments

    I used three arrays to store all the values from and, or and xor operations. And made three different functions to find the maximum of them under the threshold. But I'm pretty confused with my own code and it doesn't work. What did I do wrong?

    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <stdlib.h>
    
    int maxValue_and( int and[], int k)
    {
        int p, maxValue_a;
        maxValue_a=and[0];
    
        for (p=0; p<=5000; p++)
            {
            if (and[p]>maxValue_a)
            maxValue_a=and[p];
            }   
    
        if (maxValue_a<k)
        {
            printf("%d\n", maxValue_a);
        }
        else printf("0\n");
    }
    
    int maxValue_or( int or[], int k)
    {
        int p, maxValue_o;
        maxValue_o=or[0];
    
        for (p=0; p<=5000; p++)
            {
            if (or[p]>maxValue_o)
            maxValue_o=or[p];
            }   
    
        if (maxValue_o<k)
        {
            printf("%d\n", maxValue_o);
        }
        else printf("0\n");
    }
    
    int maxValue_xor( int xor[], int k)
    {
        int p, maxValue_x;
        maxValue_x=xor[0];
    
        for (p=0; p<=5000; p++)
            {
            if (xor[p]>maxValue_x)
            maxValue_x=xor[p];
            }   
            
        if (maxValue_x<k)
        {
            printf("%d\n", maxValue_x);
        }
        else printf("0\n");
    }
    
    int calculate_the_maximum(int n, int k, int and[], int or[], int xor[])
    {
      int arr[n];
        for (int i = 0; i <= n-1; i++)
        {
            arr[i]=i+1;
        }
        
        for (int j = 0; j <= n-1; j++)
        {
            for (int k = 0; k <= n-1; k++)
            {
                if (arr[j]==arr[k])
                {
                    k++;
                }
                
                int l;
                l=0;
    
                int and[5000];
                int or[5000];
                int xor[5000];
    
                and[l] = arr[j]&arr[k];
                or[l] = arr[j]|arr[k];
                xor[l] = arr[j]^arr[k];
    
                l++;
            }
            
        }
    
        return and[5000];
        return or[5000];
        return xor[5000];
    }
    
    int main(int and[], int or[], int xor[])
    {
        int n, k;
      
        scanf("%d %d", &n, &k);
        
        maxValue_and(and, k);
        maxValue_or(or, k);
        maxValue_xor(xor, k);
     
        return 0;
    }