Feb 7, 2022

HackerRank -Pointers in C (C Language)

Operations on pointers-finds the sum and difference between numbers given.

 #include <stdio.h>
void update(int* a , int* b) {

    int temp = *a;
    *a = temp + *b;
    *b = temp - *b;
    if (*b < 0)
    {
        *b *= (-1);
    }

}

int main() {
    int a , b;
    int* pa = &a , * pb = &b;
    printf("Enter two Numbers : ");
    scanf("%d %d" , &a , &b);
    update(pa , pb);
    printf(" sum : %d\n Difference : %d" , a , b);

    return 0;
}

No comments:

Post a Comment

Comparing two files in C language.

Operations on More than one File.    # include < stdio.h > # include < stdlib.h > # include < string.h > int main ( int ...