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

SAP Tcodes

zme27 - Automatic STO creation mmbe - Stock Overview, Material, Batch me51n - Create Purchase Requisition me21n - Create Purchase Order me59...