Sort by

recency

|

1146 Discussions

|

  • + 0 comments

    void update(int *a,int *b) { int x = *a + *b; //initializing pointers addition inside variable. int diff = *a - *b; //initializing pointers difference inside variable.

    if(diff < 0){
        diff = -diff;        //or you can use the abs( ) function for mod.
    }
    
    *a = x;
    *b = diff;
    

    }

  • + 0 comments

    void update(int *a,int *b) { int num1 = (*a); int num2 = (*b); num1 = (*a) + (*b); num2 = (*a) - (*b); if (num2 < 0) { num2 = -num2; } *a = num1; *b = num2;

    }

  • + 0 comments

    void update(int *a,int *b) { int sum= (*a)+(*b); int diff= abs((*a)-(*b));
    (*a)=sum; (*b)=diff; } this may help :)

  • + 0 comments

    Hey, this is my code. Insights would be appreciated. Happy learning!

    #include <stdio.h>
    #include <math.h>
    
    void update(int *a,int *b) {
        // Complete this function 
        int temp;``
        temp = *a;  
        (*a) = (*a) + (*b);
        (*b) = abs((temp)-(*b));
    }
    
  • + 0 comments

    Using Ternary Operator

    void update(int *a,int *b) {
        int x=*a + *b;
        int diff=*a-*b;
        int y=(diff<0 ? -diff : diff;
        *a=x;
        *b=y;
    }