Swapping of given two values using temporary variable

 Program:

#include<stdio.h>
#include<conio.h>
void main()
{
    int a, b, t;
    clrscr();
    printf("Enter any Two Numbers : ");
    scanf("%d%d", &a, &b);
    printf("\nBefore Swapping :");
    printf("\na=%d", a);
    printf("\nb=%d\n\n", b);
    t=a;
    a=b;
    b=t;
    printf("After Swapping :");
    printf("\na=%d", a);
    printf("\nb=%d", b);
    getch();
}

Output:

Enter any Two Numbers : 10    20
Before Swapping :
a=10
b=20
After Swapping 
a=20
b=10


No comments:

Post a Comment