Wednesday, 11 March 2015

Swapping Two Numbers (using three variables) Using C


# include <stdio.h>
# include <conio.h>
void main()
{
int a, b, c ;
clrscr() ;
printf("Enter two numbers : ") ;
scanf("%d %d", &a, &b) ;
printf("\nBefore swapping : \n\n") ;
printf("a = %d \t b = %d", a, b) ;
c = a ;
a = b ;
b = c ;
printf("\n\nAfter swapping : \n\n") ;
printf("a = %d \t b = %d", a, b) ;
getch();
}


RUN 1 :
~~~~~~~
Enter two numbers : 10 20
Before swapping :
a = 10 b = 20
After swapping :
a = 20 b = 10

No comments:

Post a Comment