Monday, 14 March 2016

Hacker Rank Solution Program In C++ For "Pointer"

#include <stdio.h>

void update(int *a,int *b)
{
    int temp = *a;
    *a = *a + *b;
    *b = temp - *b;

    if(*b < 0){
        *b = -(*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;
}

Output:-

programmingwithbasics

No comments:
Write comments

Recommended Posts × +