jeudi 17 novembre 2016

How to compare multiple equations with each other?

I created an array of random numbers in ascending order using bubbleSort function, printed numbers that have a pair to them (x = x) and now I'm wanting to test, if I can find any numbers for

(x = x) = (x/2 = x/2), or (x*2 = x*2) = (x = x)

Basically I need a number (e.g. 6, must be in a list two times) and number multiplied by two (e.g. 12, also must be in a list two times)

As i realized, comparing two equations doesn't go verry well with C. The current thing I have is this:

   for(i=0; i<n; i++){        
    if(arr_2[i] == s){printf("Something");}
    if(arr_2[i] == arr_2[i+1]){
//printing something       
        printf("\n\n%d == %d\n", arr_2[i], arr_2[i+1] );
//s is equal to 0, therefore we will assign new value and also assign the same value to c      
        if(s = 0){s = (arr_2[i]*2);
        memcpy(&c, &s, sizeof(s));}
//c is equal s        
        if(c = s){c = (arr_2[i]*2);
        memcpy(&a, &c, sizeof(c));}

      }
     }

Solutions like this seem to be very messy in my case, as I want the array to be longer and therefore this means creating a lot of integers and having long repetitive lines of code. This one also doesn't work, because the if statement is valid for all (couldn't think of anything that fills one variable at a time).

I would really like to have an array of a format (6, 12, 45, 90...) to later work with.

Could anyone help me?

Aucun commentaire:

Enregistrer un commentaire