+ 1

could not figure out!! the a sample test case failed!

#include <stdio.h> void update(int *a,int *b) { // Complete this function if (*a > *b) { *a = *a + *b; *b = (*a - *b) - *b; } else *a = *a + *b; *b = *b - (*a - *b); } int main() { int a, b; int *pa = &a, *pb = &b; scanf("%d %d", &a, &b); update(pa, pb); printf("%d\n%d", a, b); return 0; } The above one is the code.. one of the same test case is two inputs "3514 2122" and the expected output is "5636 1392" but my output is "5636 -2852" the problem statement is "You have to complete the function void update(int *a,int *b), which reads two integers as argument, and sets 'a' with the sum of them, and 'b' with the absolute difference of them." input is handled automatically.

15th Feb 2019, 4:48 AM
Duna000
Duna000 - avatar
2 Antworten
+ 2
Thats great.. Serena!!!! that worked like magic.. however other test cases worked fine (edit: even without the braces in the else part).. could you give me a little more explanation..!
15th Feb 2019, 5:59 AM
Duna000
Duna000 - avatar
+ 1
Yeah got it serene! I ll play with it :)
15th Feb 2019, 11:14 PM
Duna000
Duna000 - avatar