Monday, October 19, 2020

swapping numbers in c (2 unique different methods)

First Method:

#include <stdio.h>

int main()

{

    int a, b, c;

    printf("Enter A & B:");

    scanf("%d%d", &a, &b);

    printf("Before swapping: a = %d, b = %d", a, b);

    c=a;

    a=b;

    b=c;

    printf("\nAfter swapping: a = %d, b = %d", a, b);

    return 0;

}


Second Method:

#include <stdio.h>

int main()

{

    int a, b, c;

    printf("Enter A & B:");

    scanf("%d%d", &a, &b);

    printf("Before swapping: a = %d, b = %d", a, b);

    a=a+b;

    b=a-b;

    a=a-b;

    printf("\nAfter swapping: a = %d, b = %d", a, b);

}

No comments:

Post a Comment

2019 wasn’t just a year—it was a whole era.From lectures to late nights, chaos to clarity… every frame built a story I’m still living ✨

Video Link The video contains snaps from 2019 throwback ones when i was doing my masters studies from university of surrey, guildford, londo...